HomeHeap / Priority Queue
Heap / Priority Queue
Always pull the best element next — top-k, streaming, merging.
21 shown
- Kth Largest ElementA size-k min-heap of the biggest so faranimatedMedium
- Merge K Sorted ListsHeap of list heads picks the next nodeanimatedHard
- Practice problems
- Heaps (Theory Video)A complete tree stored as an arrayEasy
- Implement Min HeapSift up on insert, sift down on extractMedium
- Check if an array represents a min heapCheck every parent against its childrenMedium
- Convert Min Heap to Max HeapHeapify from the last internal node backwardsMedium
- K-th Largest element in an arrayA min-heap of size kanimatedMedium
- Kth smallest element in an arrayA max-heap of size kanimatedMedium
- Sort K sorted arrayA heap of size k+1 is all you needEasy
- Replace Elements by Their RankSort the distinct values, then map backEasy
- Task SchedulerThe most frequent task sets the skeletonMedium
- Hand of StraightsAlways start a group at the smallest card leftMedium
- Design TwitterMerge the followees' feeds with a heapMedium
- Minimum Cost to Connect SticksAlways join the two shortestMedium
- Kth largest element in a stream of running integersHold exactly k elementsanimatedHard
- Maximum Sum CombinationSort both, expand from the biggest pairHard
- Find Median from Data StreamTwo heaps facing each otherHard
- Top K Frequent ElementsCount, then bucket by frequencyMedium
- K Closest Points to OriginMax-heap of size k on squared distanceMedium
- Find K Closest ElementsBinary search the window's left edgeMedium
- Median from Data StreamMax-heap for the low half, min-heap for the highMedium