622. Task Scheduler (Greedy + Queue)

MediumStackQueueGreedy

Given tasks (each a character) and a cooldown n, identical tasks must be at least n intervals apart; each interval runs one task or idles. Return the minimum number of intervals to finish all tasks. The input is JSON {tasks, n}.

Input: JSON {tasks, n}.

Output: Integer — the minimum number of intervals.

Examples

Example 1
Input: {"tasks":["A","A","A","B","B","B"],"n":2}
Output: 8
Explanation: A B idle repeated.
Example 2
Input: {"tasks":["A","A","A","B","B","B"],"n":0}
Output: 6
Explanation: No cooldown.
Example 3
Input: {"tasks":["A"],"n":3}
Output: 1
Explanation: Single task.

Constraints

Asked by

AmazonOracleAppleMicrosoftGoogleMeta
Solve this problem in the editor →