Skip to content

London | 26-Jul-SDC | Roman Sanaye | Sprint 2 | Improve code with pre-computing - #256

Open
RomanSanaye wants to merge 3 commits into
CodeYourFuture:mainfrom
RomanSanaye:improve-code-with-precomputing
Open

RomanSanaye wants to merge 3 commits into
CodeYourFuture:mainfrom
RomanSanaye:improve-code-with-precomputing

Conversation

@RomanSanaye

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

  • Optimized find_longest_common_prefix by introducing lexicographical sorting as a pre-computation step.
  • Reduced time complexity from $O(N^2)$ to $O(N \log N)$, enabling large datasets (such as the 1-million-item test case) to pass efficiently.
  • Left the existing test suite and helper functions completely untouched as required.

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 14, 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.

  • Could you use complexity to explain how the new implementation is better than the original implementation?

  • Could you also improve the implementation in count_letters?

@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 15, 2026
@RomanSanaye

Copy link
Copy Markdown
Author

Hi @cjyuan ,
Thanks for the feedback!

  1. Longest Common Prefix:** I've added a comment explaining how sorting the list first allows us to check only adjacent pairs, reducing the time complexity from O(N^2) to O(N log N).
  2. count_letters: I've refactored the function to use sets for character collection. By replacing the inner string search (in s) with O(1) set lookups, the time complexity drops from O(N^2) to O(N).

@RomanSanaye RomanSanaye added the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Oct 15, 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.

Well done!

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants