generated from CodeYourFuture/Module-Template
-
-
Notifications
You must be signed in to change notification settings - Fork 28
Sheffield | 25-SDC-Nov | Hassan Osman | Sprint 2 | Improve code with precomputing #135
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HassanOHOsman
wants to merge
8
commits into
CodeYourFuture:main
Choose a base branch
from
HassanOHOsman:feature/improve-code-with-precomputing
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+37
−13
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
68984ec
Return empty string when fewer than two strings are provided
HassanOHOsman 0278156
if the list of strings has at least 2 items, first thing, sort the li…
HassanOHOsman 237d8bc
update the for loop inside find_longest_common_prefix function so tha…
HassanOHOsman 5187863
collect all lowercase letters present in s string into a set beforehand
HassanOHOsman dc47abb
update the 2nd loop to check agaisnt the pre-calcualted lowercase let…
HassanOHOsman fcbbe6b
Correctly indent line 15
HassanOHOsman 0b395e3
Use "Big O Notation" to explain why the new implementation is more ef…
HassanOHOsman a7cdf3b
Use "Big O Notation" to explain why the new implmentation is more eff…
HassanOHOsman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 17 additions & 4 deletions
21
Sprint-2/improve_with_precomputing/count_letters/count_letters.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,27 @@ | ||
| def count_letters(s: str) -> int: | ||
| """ | ||
| count_letters returns the number of letters which only occur in upper case in the passed string. | ||
| """ | ||
| only_lower = set() | ||
| for letter in s: | ||
| if letter.islower(): | ||
| only_lower.add(letter) | ||
|
|
||
| only_upper = set() | ||
| for letter in s: | ||
| if is_upper_case(letter): | ||
| if letter.lower() not in s: | ||
| if letter.lower() not in only_lower: | ||
| only_upper.add(letter) | ||
| return len(only_upper) | ||
|
|
||
|
|
||
| def is_upper_case(letter: str) -> bool: | ||
| return letter == letter.upper() | ||
|
|
||
|
|
||
|
|
||
| """ | ||
| The old implementation scans through the entire string for every uppercase letter | ||
| we check against, therefore complexity in the worst case is O(n^2). However, in the | ||
| new implementation the lowercase letters a store beforehand in a set. This allows | ||
| checking against every uppercase letter without scanning through the entire string. | ||
| As a result, the complexixty time goes down to O(n) with the new implementation. | ||
|
|
||
| """ |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n log n * mcould be easily misinterpreted asn log (n * m). You probably meanm * n log n.