NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | improve with precomputing#172
Open
TzeMingHo wants to merge 4 commits into
Open
NW | 26-SDC-Mar | TzeMing Ho | Sprint 2 | improve with precomputing#172TzeMingHo wants to merge 4 commits into
TzeMingHo wants to merge 4 commits into
Conversation
cjyuan
reviewed
Jun 22, 2026
cjyuan
left a comment
There was a problem hiding this comment.
Code looks good.
Could you use Big O notation to quantify the improvement achieved by the new implementation? A brief comparison of the time complexity before and after the change would be helpful.
cjyuan
reviewed
Jun 23, 2026
| return longest | ||
|
|
||
| # before changes, it was N^2, bacause it got a for loop inside a for loop | ||
| # after changes, it is N + N. The first N for sorted, and another N for the loop. |
There was a problem hiding this comment.
Could you lookup the complexity of sorted() in Python?
Author
There was a problem hiding this comment.
The worst case for sorted is NlogN, when the list is randomly ordered.
There was a problem hiding this comment.
O(n log n) is the optimal average-case time complexity achievable by any comparison-based sorting algorithm.
An O(n) complexity approach is possible but that would involve writing a lot of code. 😄
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Learners, PR Template
Self checklist
Changelist
I have attempted with sorted and set