awesome-everything RU
↑ Back to the climb

Algorithms from zero

Heaps & priority queues: interview drill

Crux Timed heap and priority-queue problems from the NeetCode-150, with progressive hints — solve each cold, then narrate the complexity.
Your altitude — climbing toward senior
ZeroJuniorMiddleSenior
You are at senior altitude — in orbit
◷ 120 min

You understand the heap. Interviews test whether you can spot when “I only need the k best” beats sorting, reach for a priority queue under a timer, and explain the cost out loud.

Goal

Solve each problem before you reveal a hint, hit the target time, and narrate the time and space complexity as if an interviewer were listening. The hints exist for when you are genuinely stuck — they nudge you toward the pattern, never the full solution.

Five NeetCode-150 problems on the heap and priority-queue pattern this unit teaches. Set a timer, solve each cold without looking at a hint, then say the time and space complexity out loud before you move on. Reveal a hint only when you are truly stuck — the hints nudge, they never hand you the answer.

0/5 solved

heap priority queue

#703 Kth Largest Element in a StreamEasy10m
AmazonMeta
Follow-up (aloud)

Why a min-heap of size k rather than a max-heap of everything? Narrate the per-add complexity and how it depends on k, not n.

#1046 Last Stone WeightEasy10m
Amazon
Follow-up (aloud)

Each round shrinks the heap by at least one. State the overall time complexity and why the heap operations dominate it.

#215 Kth Largest Element in an ArrayMedium15m
AmazonMeta
Follow-up (aloud)

Quickselect averages O(n) but its worst case is O(n²). What input triggers the worst case, and how does a randomised pivot defend against it?

#973 K Closest Points to OriginMedium15m
AmazonGoogle
Follow-up (aloud)

Compare the size-k heap approach to a quickselect partition by distance. State each one's time complexity and when you'd pick which.

#621 Task SchedulerMedium20m
MetaAmazon
Follow-up (aloud)

Argue why the greedy 'always run the most frequent ready task' is optimal here. What would break if two tasks tie for the maximum count?

Recap

Mark each problem solved once you finished it cold, inside the target time, and could state the complexity without hesitation. Come back in a few days and re-solve the ones you marked — spaced revisits are what turn a recognised pattern into a reflex.

Continue the climb ↑Graph representations
shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.