London | 26-SDC-March | Zobeir Rigi | Sprint 2 | Improve code with precomputing - #210
London | 26-SDC-March | Zobeir Rigi | Sprint 2 | Improve code with precomputing#210Zobeir-Rigi wants to merge 2 commits into
Conversation
cjyuan
left a comment
There was a problem hiding this comment.
Code are correct.
Could you use complexity to explain how the new implementation is better than the original implementation?
Sure, 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). |
|
All good. |
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:
All provided tests pass.