Given a list of tasks (each labeled by a letter) and a positive integer n, schedule the tasks on a single CPU. Between two occurrences of the SAME task, the CPU must rest for at least n slots (it may do other tasks during cooldown, or sit idle). Return the MINIMUM total number of time units needed to finish all tasks.
Constraints: 1 ≤ tasks.length ≤ 10^4 · tasks[i] uppercase English letter · 0 ≤ n ≤ 100.
Eight tasks: [A, A, A, B, B, B, C, C]. Between two occurrences of the SAME task, the CPU needs a cooldown of n=2 slots — that is, two slots in which the CPU must do something else (or sit idle). Schedule them. How few time units can you pull this off in?
How many time slots does the optimal schedule need?