Task Scheduler
Given task counts and a cooldown n between identical tasks, return the minimum total intervals.
Try it
Step through the core mechanic. The simulator below runs the greedy shape this problem is built on.
No dedicated step-through for this one yet. The shape is Greedy: its pattern page has the interactive walkthrough, the reference implementation, and a five-problem progression that this problem sits inside.
The approach
The most frequent task dictates the frame: (maxCount−1)·(n+1) slots, plus the number of tasks tied for the max. The answer is max(that frame, total tasks): idle only when tasks cannot fill the gaps.
| Aspect | Value |
|---|---|
| Pattern | Greedy |
| Recognise it by | Schedule with a cooldown: fill gaps around the busiest task. |
| Time complexity | O(n) |
| Space complexity | O(1) |
| Difficulty | Medium |
Who asks it
Companies known to ask this problem, from public LeetCode company-tag aggregations. A signal of where to expect it, not a guarantee.