Key Patterns to Master
- Top K Elements: Maintaining a heap of size $K$.
- Two Heaps: For tracking medians or balanced sets.
- K-way Merge: Combining multiple sorted inputs.
Hand-Picked Problems
| Problem | Difficulty | Key Pattern |
|---|---|---|
| Kth Largest Element in an Array | Medium | Min-Heap of size K |
| Top K Frequent Elements | Medium | Frequency Map + Heap |
| Merge k Sorted Lists | Hard | Head Tracking |
| Find Median from Data Stream | Hard | Max-Heap + Min-Heap |
| K Closest Points to Origin | Medium | Distance-based Heap |
| Reorganize String | Medium | Max Freq + Cooldown |
| Task Scheduler | Medium | Greedy + Priority Queue |
| Kth Largest Element in a Stream | Easy | Streaming Heap |
| Smallest Range Covering Elements from K Lists | Hard | Multi-list Sliding Heap |
| Meeting Rooms II | Medium | Chronological Heap |
Interview Tip
Always mention the Heapify operation ($O(n)$) if you are building a heap from an entire array at once. 埋