Back to DSA

Task Scheduler

medium
Acceptance: 44%
HeapGreedyArray

A CPU must execute a set of tasks represented by characters. Between two executions of the same task there must be at least n intervals of cooldown (other tasks or idle slots). Determine the minimum total number of intervals the CPU needs to complete every task.

Examples

Example 1:
Input:tasks = ['X','X','X','Y','Y','Y'], n = 2
Output:8
Example 2:
Input:tasks = ['X','X','X','Y','Y','Y'], n = 0
Output:6

Hints

00:00
1234567