Search topics...

Task Scheduler

medium
os-flavorTime: O(n)Space: O(1)Frequency: 4

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.