Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 2 | Improve code with precomputing#135
Open
HassanOHOsman wants to merge 8 commits intoCodeYourFuture:mainfrom
Open
Conversation
…st alphabetically
…t each string in the list is compared with the one comes after it. This is a lot more efficient
…ters set instead of s string
cjyuan
reviewed
Mar 2, 2026
cjyuan
left a comment
There was a problem hiding this comment.
Can you use complexity to explain how the new implementation are better than the original implementation?
| for i in range(len(strings) - 1): | ||
| common = find_common_prefix(strings[i], strings[i + 1]) | ||
| if len(common) > len(longest): | ||
| longest = common |
…ficient than the original
…icient than the previous one
Author
Just did. |
cjyuan
reviewed
Mar 4, 2026
| mentation compares each string with every single while looping through | ||
| nested for loop. | ||
| As a result, the compelxity time drops from the original O(n^2 * m) to | ||
| around O(n log n * m). |
There was a problem hiding this comment.
n log n * m could be easily misinterpreted as n log (n * m). You probably mean m * n log n.
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.
Self checklist
In this pull request, I introduced pre-computation in order to speed up the implementations in "common_prefix" and "count_letters" directories.