Last updated
Was this helpful?
Last updated
Was this helpful?
Given a non-empty list of words, return thekmost frequent elements.
Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word with the lower alphabetical order comes first.
Example 1:
Example 2:
Note:
You may assume k is always valid, 1 ≤ k ≤ number of unique elements.
Input words contain only lowercase letters.
Follow up:
Try to solve it in O(nlogk) time and O(n) extra space.