Search topics...
All Problems

Task Scheduler

Solution Approach
Was this helpful?
Mediumos-flavorExpected: O(n) time, O(1) space

Problem

Given tasks and a cooldown interval n between same tasks, return the minimum intervals the CPU needs to finish all tasks.

Example 1:

Input: tasks = ['A','A','A','B','B','B'], n = 2
Output: 8
Explanation: A -> B -> idle -> A -> B -> idle -> A -> B

Example 2:

Input: tasks = ['A','A','A','B','B','B'], n = 0
Output: 6
Explanation: No cooldown needed, so all 6 tasks run back-to-back.
Reference solution unlocks after your first submission
Loading...