Max-heap of available counts; queue holds cooling tasks.
Warm-up MCQs
1. For Kth Largest, what heap choice matches the invariant?
Source invariant: “A heap hands you the best remaining element in O(log n) per update; keep a min-heap of size k to hold the k largest.”
2. A Top K Frequent attempt pushes (-count, value), then pops past k. What breaks?
Source invariant: “A heap hands you the best remaining element in O(log n) per update; keep a min-heap of size k to hold the k largest.”
3. Which heap contents keep Merge K Sorted Lists honest?
Source invariant: “The heap holds one head per list; pop the smallest, push its successor, repeat until every list is drained.”
4. What split makes the median available after updates?
Source invariant: “A max-heap of the lower half and a min-heap of the upper half, kept balanced, put the median at the tops.”
5. What does the heap choose from during Task Scheduler?
Source invariant: “Always run the most frequent available task; a cooldown queue holds tasks until they are legal again.”
6. Why does Merge K use O(N log k) time?
Source invariant: “The heap holds one head per list; pop the smallest, push its successor, repeat until every list is drained.”
Self-check gate
Pass tonight if
All three chosen problems compile and pass on run one or two, and you can answer min-heap or max-heap, and what lives in it? for all five menu problems without notes.
Failure path: if any attempt fails after run two, or any heap drill answer is unclear, write WA: <root cause> and add that exact problem to the next revision queue.