Study Notes
Problem editorialmedium

Top K frequent words

Count everything, then rank by two rules at once: most frequent first, ties broken alphabetically. The real algorithm lives in the comparator.

15 min read·time O(N + U log K)·space O(U)
Count then rankComparator designBounded heap