Skip to content

Birmingham | 26-Jul-SDC | Merve Reis | Sprint 2 | improve with precomputing - #248

Open
mervereis wants to merge 2 commits into
CodeYourFuture:mainfrom
mervereis:sprint2-improve-with-precomputing
Open

mervereis wants to merge 2 commits into
CodeYourFuture:mainfrom
mervereis:sprint2-improve-with-precomputing

Conversation

@mervereis

@mervereis mervereis commented Oct 13, 2026 •

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Task code

CYF-1183

Changelist

@github-actions

This comment has been minimized.

@mervereis mervereis added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 13, 2026

@cjyuan cjyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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 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
@mervereis

Copy link
Copy Markdown
Author

Code looks good.

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).

@cjyuan

cjyuan commented Oct 15, 2026

Copy link
Copy Markdown

What about the complexity of original and the improved find_longest_common_prefix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed Volunteer to add when completing a review with trainee action still to take.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants