Skip to content

London | 26-SDC-March | Zobeir Rigi | Sprint 2 | Improve code with precomputing - #210

Open
Zobeir-Rigi wants to merge 2 commits into
CodeYourFuture:mainfrom
Zobeir-Rigi:improve-code-with-precomputing
Open

London | 26-SDC-March | Zobeir Rigi | Sprint 2 | Improve code with precomputing#210
Zobeir-Rigi wants to merge 2 commits into
CodeYourFuture:mainfrom
Zobeir-Rigi:improve-code-with-precomputing

Conversation

@Zobeir-Rigi

Copy link
Copy Markdown
  • 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

I originally completed all the Sprint 2 exercises in one PR, but the validation expected separate PRs for each issue. This PR contains only the "Improve code with precomputing" exercise.

Improved performance by introducing precomputing techniques in:

  • common_prefix
  • count_letters

All provided tests pass.

@Zobeir-Rigi Zobeir-Rigi added 📅 Sprint 2 Assigned during Sprint 2 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. Module-Complexity The name of the module. labels Jul 6, 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 are correct.

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 Jul 9, 2026
@Zobeir-Rigi

Copy link
Copy Markdown
Author

Code are correct.

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

Sure,
For common_prefix, the original solution compared every pair of strings, resulting in O(n²) complexity. By sorting the strings first (O(n log n)) and then comparing only neighbouring strings, the overall complexity is reduced to O(n log n).

For count_letters, the original solution checked membership in the string for every character, resulting in O(n²) complexity. The refactored version pre-computes a set of characters in O(n), allowing O(1) lookups and reducing the overall complexity to O(n).

@cjyuan cjyuan added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Reviewed Volunteer to add when completing a review with trainee action still to take. labels Jul 14, 2026
@cjyuan

cjyuan commented Jul 14, 2026

Copy link
Copy Markdown

All good.

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. Module-Complexity The name of the module. 📅 Sprint 2 Assigned during Sprint 2 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants