Question bankPricingSign in

Task Scheduling with Cooldown

GreedyMedium1:30

You have a list of tasks to execute on a single processor. After completing a task, there is a mandatory cooldown period of k intervals before the same task can run again. During cooldown, the processor can run a different task or sit idle. Find the minimum number of intervals needed to execute all tasks.

For example, given tasks = ["A","A","A","B","B","B"] and k = 2, one optimal schedule is A B idle A B idle A B, requiring 8 intervals.

Explain your approach and state the time and space complexity.

How to approach it

  • Hint 1

    The task with the highest frequency determines the minimum schedule length.

  • Hint 2

    Imagine placing the most frequent task first with k-sized gaps between each occurrence. This creates a frame with idle slots that other tasks fill.

  • Hint 3

    The minimum intervals = max(total tasks, (maxFreq - 1) * (k + 1) + countOfTasksWithMaxFreq).

Ready to answer it out loud?

Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.

Practising needs an invite code. Join the waitlist and we’ll send you one.