MediumVery High Frequency30 min
Top K Elements Pattern
Find the K largest/smallest/most frequent elements using a size-K heap.
Use a min-heap of size k for top-k-largest, max-heap of size k for top-k-smallest. O(n log k) is better than O(n log n) sort for large n.