Given CPU tasks (character array) and a cooldown n, each same task must wait n intervals before rerunning. Return the minimum number of intervals to finish all tasks.
Input: tasks = ["A","A","A","B","B","B"], n = 2
Output: 8
Explanation: A→B→idle→A→B→idle→A→B
Topics: greedy, heap, arrays
Asked by: Amazon, Google, Meta, Microsoft, Bloomberg
Time complexity: O(n). Space complexity: O(1).