You are given an array of CPU `tasks`, each represented by a letter A to Z, and a cooling time `n`. Each cycle or interval allows the completion of one task. Tasks can be completed in any order, but there's a constraint: identical tasks must be separated by at least `n` intervals due to cooling time. Return the minimum number of intervals required to complete all tasks.
Greedy via Max-Heap
To minimize idle time, we should always prioritize the task with the highest remaining frequency. We use a Max-Heap to track frequencies. When a task is executed, it enters a 'cooldown queue' where it waits for `n` intervals before it can be added back to the heap.