-
Notifications
You must be signed in to change notification settings - Fork 41
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
Time - Haben #23
base: master
Are you sure you want to change the base?
Time - Haben #23
Conversation
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.
Not bad Haben, they both work. Your top_k_elements works, but uses an O^2 solution. I encourage you to think of an alternative, sorting is one way, there is also another even better.
# Time Complexity: O(n) | ||
# Space Complexity: O(n) | ||
def grouped_anagrams(strings) |
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.
👍
# Time Complexity: O(n^2) | ||
# Space Complexity: O(n) | ||
|
||
def top_k_frequent_elements(list, k) |
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.
👍 Could you use a sort to improve the time complexity to O(n log n) or better?
# each element in another, sorted based on descending # freqency | ||
elements = [] | ||
elements_frequency = [] | ||
hash1.each do | key, frequency | |
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.
Could you sort the hash key-value pairs here or select the max k elements instead?
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions