Top K Frequent Words
Problem Given a list of words, return the k most frequent words, sorted by frequency (highest first) and breaking ties lexicographically (smallest first).
Input / Output
- Input: a list of words
words, an integerk. - Output: the k most frequent words in the required order.
Constraints
- 1 ≤ words.length ≤ 10^4.
- Ties in frequency are broken by ascending lexicographic order.
Example
["i","love","leetcode","i","love","coding"], k=2 →["i","love"](both appear twice; "i" < "love").
added …