Top-K trick
A min-heap of size k stores the k largest: root is the threshold. Replace when a larger candidate arrives.
Lesson
Get min/max in O(1), insert/pop in O(log n) — Top-K and scheduling.
Loading solution…
A min-heap of size k stores the k largest: root is the threshold. Replace when a larger candidate arrives.
Heap Top-K visualizes sift-up / sift-down as elements stream in.
Showing 24 of the related problems in the 1000-question bank.
Merge k Sorted Lists
Heap
Kth Largest Element in an Array
Heap
Sliding Window Maximum
Monotonic Deque
Find Median from Data Stream
Two Heaps
Top K Frequent Elements
Heap
Task Scheduler
Greedy / Heap
Kth Largest Element in a Stream
Heap
Network Delay Time
Dijkstra
Cheapest Flights Within K Stops
Bellman / Dijkstra
K Closest Points to Origin
Heap
Smallest Range Covering Elements — Practice 26
Heap
Find K Pairs with Smallest Sums — Practice 29
Heap
Last Stone Weight — Practice 32
Heap
IPO — Practice 34
Heap
Reorganize String (Heap) — Practice 37
Heap
Kth Smallest Element in Sorted Matrix — Practice 40
Heap
Maximum Performance of a Team — Practice 42
Heap
Smallest Range Covering Elements — Practice 45
Heap
Find K Pairs with Smallest Sums — Practice 48
Heap
Last Stone Weight — Practice 51
Heap
IPO — Practice 53
Heap
Reorganize String (Heap) — Practice 56
Heap
Kth Smallest Element in Sorted Matrix — Practice 59
Heap
Maximum Performance of a Team — Practice 61
Heap
Got the lesson?
Mark Heaps & Priority Queues as understood when the ideas stick.