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=2

Output: 8 intervals

Example 2

['A','A','A','B','C','D'], n=2

Output: 7 intervals

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Arrays problems