← Heap / Priority Queue

Pattern Recognition Drill

#57 — Min-heap push and pop

Easy Heaps

The Problem

Demonstrate pushing and popping elements from a min-heap.

What approach would you use?

Think about it before scrolling down.

Key Signals

Heap / Priority Queue

heapq.heappush inserts in O(log n), heappop removes min in O(log n). Array-based complete binary tree.

Common Trap

Python's heapq is a min-heap. For max-heap, negate values or use a wrapper.

← #56 #58 →