LC 621
LeetCode 621 · Medium

Task Scheduler

Given task counts and a cooldown n between identical tasks, return the minimum total intervals.

Greedy → · High frequency · Solve on LeetCode →

Try it

Step through the core mechanic. The simulator below runs the greedy shape this problem is built on.

Walk the pattern

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.

AspectValue
PatternGreedy
Recognise it bySchedule with a cooldown — fill gaps around the busiest task.
Time complexityO(n)
Space complexityO(1)
DifficultyMedium

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.