Heap Practice Questions
Ten classic heap problems. Every one of them is the same sentence in disguise: “of these many things, give me the most extreme one — repeatedly.” Recognize that pattern and a heap becomes the obvious tool.
All the solutions below use the standard library’s priority queue rather than rolling our own heap. That’s the right call in real code — the implementation is identical and well-tested. We covered the from-scratch version on the Operations page.
Easy
| Problem | Pattern | Status |
|---|---|---|
| Last Stone Weight | Repeatedly extract the two largest | Available |
| Kth Largest Element in an Array | Size-K min-heap | Available |
| Kth Largest Element in a Stream | Online size-K min-heap | Available |
Medium
| Problem | Pattern | Status |
|---|---|---|
| Top K Frequent Elements | Hash count + size-K min-heap | Available |
| K Closest Points to Origin | Size-K max-heap of distances | Available |
| Sort Characters by Frequency | Counter + heap (or bucket) | Available |
| Task Scheduler | Max-heap + cooldown queue | Available |
| Reorganize String | Max-heap by frequency | Available |
Hard
| Problem | Pattern | Status |
|---|---|---|
| Merge K Sorted Lists | Min-heap of list heads | Available |
| Find Median from Data Stream | Two heaps (max + min) | Available |
More Practice (Coming Soon)
| Problem | Pattern | Status |
|---|---|---|
| Sliding Window Median | Two heaps with lazy deletion | Coming Soon |
| Connect Ropes with Minimum Cost | Min-heap, repeated merging | Coming Soon |
| IPO / Maximum Capital | Two heaps (capital + profit) | Coming Soon |
| Furthest Building You Can Reach | Min-heap of brick costs | Coming Soon |
| Smallest Range Covering K Lists | K-way merge with heap | Coming Soon |
| Single-Threaded CPU | Min-heap by (processing time, id) | Coming Soon |
| Maximum Performance of a Team | Min-heap, greedy iteration | Coming Soon |