You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Birmingham | 26-Jul-SDC | Merve Reis | Sprint 2 | improve with precomputing - #248
The reason will be displayed to describe this comment to others. Learn more.
Code looks good.
Could you use complexity to explain how the new implementation is better than the original implementation?
cjyuan
added
Reviewed
Volunteer to add when completing a review with trainee action still to take.
and removed
Needs Review
Trainee to add when requesting review. PRs without this label will not be reviewed.
labels
Oct 14, 2026
Could you use complexity to explain how the new implementation is better than the original implementation? @cjyuan
The original implementation has a time complexity of O(n²) because it loops through every character and uses not in s to search the entire string each time.
The improved implementation has a time complexity of O(n) because it creates a set of unique letters first. Checking whether a letter exists in a set takes O(1) on average, so we avoid repeatedly searching the whole string.
Both implementations use O(1) extra space for English letters, because there are only 52 possible uppercase and lowercase letters.
Overall, the new implementation is more efficient, especially for very long strings, because it reduces the time complexity from O(n²) to O(n).
What about the complexity of original and the improved find_longest_common_prefix?
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
ReviewedVolunteer to add when completing a review with trainee action still to take.
2 participants
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
Task code
CYF-1183
Changelist