Cooldown Scheduler
A CPU runs one task per time unit. Identical tasks (same letter) must be at least n units apart; the CPU may idle. Return the minimum number of time units needed to run every task in tasks.
The answer has a closed form. With the highest task count and the number of tasks with that count:
Examples
A guided view of the published example, not a trace of your code.
[["A","A","A","B","B","B"],2]8Start with the input values shown in this example.
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8
Explanation: idle needed
Input: tasks = ["A","A","A","B","B","B"], n = 0
Output: 6
Explanation: no cooldown
Input: tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
Output: 16
Explanation: one dominant task
Hint 1
The most frequent task sets the skeleton: f - 1 full blocks of length n + 1, then a final partial block.