AlgoViz
HomeHeap / Priority Queue

Heap / Priority Queue

Always pull the best element next — top-k, streaming, merging.

0/ 21 understood · 0%
Walkthroughs
5
Problems
21
Start here
21 shown
  1. Kth Largest ElementA size-k min-heap of the biggest so farMedium
  2. Merge K Sorted ListsHeap of list heads picks the next nodeHard
  3. Practice problems
  4. Heaps (Theory Video)A complete tree stored as an arrayEasy
  5. Implement Min HeapSift up on insert, sift down on extractMedium
  6. Check if an array represents a min heapCheck every parent against its childrenMedium
  7. Convert Min Heap to Max HeapHeapify from the last internal node backwardsMedium
  8. K-th Largest element in an arrayA min-heap of size kMedium
  9. Kth smallest element in an arrayA max-heap of size kMedium
  10. Sort K sorted arrayA heap of size k+1 is all you needEasy
  11. Replace Elements by Their RankSort the distinct values, then map backEasy
  12. Task SchedulerThe most frequent task sets the skeletonMedium
  13. Hand of StraightsAlways start a group at the smallest card leftMedium
  14. Design TwitterMerge the followees' feeds with a heapMedium
  15. Minimum Cost to Connect SticksAlways join the two shortestMedium
  16. Kth largest element in a stream of running integersHold exactly k elementsHard
  17. Maximum Sum CombinationSort both, expand from the biggest pairHard
  18. Find Median from Data StreamTwo heaps facing each otherHard
  19. Top K Frequent ElementsCount, then bucket by frequencyMedium
  20. K Closest Points to OriginMax-heap of size k on squared distanceMedium
  21. Find K Closest ElementsBinary search the window's left edgeMedium
  22. Median from Data StreamMax-heap for the low half, min-heap for the highMedium