692. Top K Frequent Words
Practice Top K Frequent Words for free on NudgeCode: Medium, Heap pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Return the k most frequent words in words, sorted from most to least frequent. Words with the same frequency are sorted in lexicographical order.
Example
words = ["i","love","leetcode","i","love","coding"], k = 2 -> ["i","love"]
Constraints
- 1 <= words.length <= 500, 1 <= words[i].length <= 10
- words[i] consists of lowercase English letters
- 1 <= k <= number of distinct words
- Follow-up: O(n log k) time