How do you schedule tasks with a cooling interval n so identical tasks are at least n apart, minimizing total time?
PICTURE THIS: DATA SPLIT
Fit on train, tune on val, report on test once.
Simple meaning
Greedy: count frequencies, use a max-heap of remaining counts and a cooldown queue of (ready_time, count).
WHY — Queue instead of guessing?
Why interviewers care about Queue:
question about Queue.
trade-offs, and what you would actually do on a DSA project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1Greedy: count frequencies, use
a max-heap of remaining counts and a cooldown queue of (ready_time, count).
- 2Fill idle slots only
when the heap is empty before the next ready time.
- 3Time is O(T log
A) for T time units and alphabet A.
- 4The formula using max
frequency is O(A) when there is no reordering constraint beyond cooling.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
Greedy: count frequencies, use a max-heap of remaining counts and a cooldown queue of (ready_time, count). Fill idle slots only when the heap is empty before the next ready time.