256. Task Scheduler — CPU Cooldown

Medium · Greedy

Given a list of CPU tasks (uppercase letters) and a cooldown period `n`, compute the minimum number of CPU intervals (including idle time) to finish all tasks. The same task must wait at least `n` intervals before running again.

Examples

Example 1
Input: tasks=["A","A","A","B","B","B"], n=2
Output: 8
Explanation: A→B→idle→A→B→idle→A→B

Constraints