Skip to main content

๐ŸŽฎ Heaps (Practice)

Companion to the Heaps & Priority Queues guide. Watch a min-heap build by sifting each new value up, then use heapq for top-K.

๐ŸŽฌ Watch it workโ€‹

Min-Heap Insert โ€” sift upStep 1 / 21
7
Insert 7 at index 0

๐Ÿ Your turnโ€‹

Loading editorโ€ฆ

๐Ÿง  Challenge yourselfโ€‹

  1. Build a max-heap using the negate trick.
  2. Implement a streaming median with two heaps.
  3. Why is heapify O(n) but k pushes O(n log n)?

Continue the path โ†’ Trees & BST