-
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 - Alicia #30
base: master
Are you sure you want to change the base?
Time - Alicia #30
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 Alicia, you hit most of the learning goals and got most of the top_k_frequent_elements
. Take a look at my comments and see if that would help you get to a solution, or if it gives you follow up questions to ask me.
Also take a look at my comments for the anagrams problem.
bucket = anagram_hash.keys.find do |b| | ||
unique_chars = b.chars.sort.join | ||
unique_chars == str.chars.sort.join | ||
end |
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.
Since you're using a hash you don't need to do a find
here.
Instead consider:
letters = str.chars.sort
if anagram_hash[letters]
anagram_hash[letters] << str
else
anagrams_hash[letters] = [str]
end
end | ||
|
||
#this doesn't pass tests — instead of grabbing the FIRST most frequent, it grabs the most frequent, period. I couldn't figure out how to do the other way | ||
return elements_hash.keys.max_by(k) { |key| elements_hash[key] } |
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.
What you can do is find the maximum value in the hash, save the key in an answer array. Then delete that entry from the hash, repeat until you have an answer array that is k length. That would be O(nk) in time complexity.
Hash Table Practice
Congratulations! You're submitting your assignment!
Comprehension Questions