-
Notifications
You must be signed in to change notification settings - Fork 8
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
Branches - Kelsey #1
base: master
Are you sure you want to change the base?
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.
Overall not bad, you've got the solutions, but your sort is O(n^2) for the kth largest, You can use the built-in sort method to do a MergeSort. You did hit the main learning goals here.
// Time Complexity: O(n) overall. Iterating over the array of strings to extract each string is O(n) where n is the length of the array. Alphabetizing each string is itself O(n) where n is the length of the word. Checking for the key in the uniqAnagrams object is O(1), and inserting an object into an array in Javascript is O(n). Pretty sure Object.keys is an O(n) situation as well. | ||
// Space Complexity: O(n). Creating a hash with a size of up to 'n' length of strings, and creating an array of subarrays with a total size that's up to 'n' length of strings. (Also creating an array 'key' that's the size of the length of one string.) | ||
function groupedAnagrams(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.
Good, but the lines are a bit long to read.
// Time Complexity: O(n). | ||
// Iterating over 'list' is O(n) where n is the length of 'list', iterating over 'uniqEls' is O(n) where n is the length of uniqEls(less than or equal to the length of 'list'). | ||
// Space Complexity: O(n). Creating a hash and an array are both O(n). | ||
|
||
function topKFrequentElements(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.
Given your two nested loops you have an O(n^2) time complexity.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions