AAlgoLoopSpaced repetition for LeetCode

Heap / Priority Queue

A heap keeps the smallest (or largest) element instantly accessible while inserts and removals stay O(log n). Use it for top-k, kth-largest, merging sorted streams, or any time you repeatedly need the current minimum or maximum.

16 LeetCode problems solved with the Heap / Priority Queue pattern. Practice them with spaced repetition so the pattern sticks.

See the full solution

The complete approach, reference solutions in 5 languages, and a step-by-step visualization — then add this problem to your spaced-repetition schedule.

Start free →