Approach Summary
Count frequencies, then min-heap of size k sorted by (frequency desc, lexicographic asc). Invert at end.
How to Recognize This Pattern
- "Top k words by frequency, ties broken alphabetically"
- Min-heap preserves k best seen so far
Complexity Analysis
Time Complexity
O(n log k)
Space Complexity
O(n)
Tags
Hash Table String Trie Sorting Heap Bucket Sort