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

Core interview problems are free with a full runner and lessons; Pro opens the complete library.

More Arrays problems