LeetCode ยท Heap

Heap / Priority Queue Problem Set

Min-heaps, max-heaps, two-heap patterns, and heap-powered graph algorithms. When you need "the K-th largest" or "the best available" โ€” reach for a heap.

Concept page: Heap / Priority Queue
DifficultyPatternProblemKey Insight
EasydesignLC 703 ยท Kth Largest Element in a StreamMin-heap of size k. Peek = kth largest. O(log k) per add.
EasysimulationLC 1046 ยท Last Stone WeightMax-heap, smash two largest repeatedly. O(n log n).
Mediumtop-kLC 215 ยท Kth Largest Element in an ArrayMin-heap of size k, or quickselect. O(n) average.
Mediumtop-kLC 347 ยท Top K Frequent ElementsFrequency map + min-heap of size k, or bucket sort. O(n).
Mediumtop-kLC 973 ยท K Closest Points to OriginMax-heap of size k by distance. O(n log k).
MediumdesignLC 355 ยท Design TwitterMerge k sorted feeds with max-heap. O(k log k) per getNewsFeed.
Mediumgreedy+heapLC 621 ยท Task SchedulerMax-heap of frequencies + cooldown queue. O(n).
Mediumgraph+heapLC 743 ยท Network Delay TimeDijkstra with a min-heap of (distance, node). Pop nearest first, skip stale entries.
HardmergeLC 23 ยท Merge k Sorted ListsMin-heap of k list heads. O(n log k).
Hardtwo-heapLC 295 ยท Find Median from Data StreamMax-heap (lower half) + min-heap (upper half). O(log n) per add, O(1) median.

โ† Back to all LeetCode categories