-
Notifications
You must be signed in to change notification settings - Fork 76
Nourhan - Spruce - C16 #54
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,45 @@ | ||
|
|
||
| from typing import OrderedDict | ||
|
|
||
|
|
||
| def grouped_anagrams(strings): | ||
| """ This method will return an array of arrays. | ||
| Each subarray will have strings which are anagrams of each other | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(nlog(n)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My guess is that you noticed your call to However, don't forget about the number of strings in the list (let's call that But the good news is that we can actually make a simplifying assumption! Since we know the strings are English words, and English words tend to be limited in length (about 5 letters on average), the effect of |
||
| Space Complexity: O(n) | ||
| """ | ||
| pass | ||
| anagrams = {} | ||
| for string in strings: | ||
| string_sorted = ''.join(sorted(string)) | ||
| if string_sorted in anagrams: | ||
| anagrams[string_sorted].append(string) | ||
| else: | ||
| anagrams[string_sorted] = [string] | ||
| return list(anagrams.values()) | ||
|
|
||
|
|
||
| def top_k_frequent_elements(nums, k): | ||
| """ This method will return the k most common elements | ||
| In the case of a tie it will select the first occuring element. | ||
| Time Complexity: ? | ||
| Space Complexity: ? | ||
| Time Complexity: O(nlog(n)) | ||
| Space Complexity: O(n) | ||
| """ | ||
| pass | ||
| elements_count = {} | ||
| for num in nums: | ||
| if num in elements_count: | ||
| elements_count[num] += 1 | ||
| else: | ||
| elements_count[num] = 1 | ||
| result = [] | ||
| count = 0 | ||
| for key, _ in sorted(elements_count.items(), key= lambda x: x[1], reverse=True): | ||
| if count < k: | ||
| result.append(key) | ||
| count += 1 | ||
| else: | ||
| break | ||
| return result | ||
|
|
||
|
|
||
|
|
||
| def valid_sudoku(table): | ||
|
|
||
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.
Looks like this
importstatement never got used. In general, just to keep the code clean, you probably want to remove unusedimportslike these.