Medium · Arrays
Task scheduler
Given an array of task letters (A–Z) and a cooldown n, return the minimum number of CPU intervals, idle ones included, needed to run every task (one task per interval) when two runs of the same letter must have at least n intervals between them.
Examples
Example 1
['A','A','A','B','B','B'], n=2Output: 8 intervals
Example 2
['A','A','A','B','C','D'], n=2Output: 7 intervals
Rebuild it in the studio
Read every interview problem free. Ten rooms need no account. A token opens a problem in full — Pro never counts.