You are given an array of CPU tasks, each labeled with a letter from A to Z. The CPU can execute one task per interval. For each interval, the CPU can either:
However, there is a cooldown interval n between two tasks with the same label. That is, there must be at least n intervals between any two executions of the same task label.
Return the minimum number of intervals required to complete all tasks.
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8
Explanation: A -> B -> idle -> A -> B -> idle -> A -> B
Each A must wait 2 intervals before the next A.
Input: tasks = ["A","A","A","A","A","A","B","C","D","E","F","G"], n = 2
Output: 16
Explanation: A -> B -> C -> A -> D -> E -> A -> F -> G -> A -> idle -> idle -> A -> idle -> idle -> A
Task A runs 6 times and dominates the schedule.
1 <= tasks.length <= 10^4tasks[i] is an uppercase English letter.0 <= n <= 100tasks = [A, A, A, B, B, B], n = 2