Skip to content

London | 26-Jul-SDC | Shaghayegh Far| Sprint 2 | Improve code with pre-computing - #258

Open
shaghayeghfar wants to merge 1 commit into
CodeYourFuture:mainfrom
shaghayeghfar:improve_with_precomputing
Open

shaghayeghfar wants to merge 1 commit into
CodeYourFuture:mainfrom
shaghayeghfar:improve_with_precomputing

Conversation

@shaghayeghfar

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

@shaghayeghfar shaghayeghfar 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.

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 15, 2026
@shaghayeghfar shaghayeghfar changed the title London | 26-Jul-SDC | Shaghayegh Far| Sprint 2 | Improve code with pre-computing Needs Review London | 26-Jul-SDC | Shaghayegh Far| Sprint 2 | Improve code with pre-computing Oct 21, 2026
@shaghayeghfar

Copy link
Copy Markdown
Author

Dear @cjyuan
thank you for taking time and check my code, I really appreciate it .

about for question :

For count_letters, the original implementation checks whether each uppercase letter's lowercase version exists in the string. The in operation on a string takes O(n) time, so repeating it for each character gives O(n²) time complexity.

The new implementation uses sets to collect uppercase and lowercase letters in one pass, then checks membership in the lowercase set. Set lookups take O(1) on average, so the overall time complexity is O(n) on average.

Therefore, the new implementation improves the time complexity from O(n²) to O(n), making it more efficient for longer strings.

@shaghayeghfar shaghayeghfar added Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Oct 21, 2026
@cjyuan

cjyuan commented Oct 21, 2026

Copy link
Copy Markdown

How about find_longest_common_prefix()? How much better is the new implementation compare to the original one?

@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 21, 2026
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