599. Task Scheduler — Simple Version

EasyStackQueueGreedy

Given a list of tasks (each a character) and a cooldown n, the same task must be separated by at least n intervals; each interval runs one task or is idle. Return the minimum number of intervals needed 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 A B idle A B.
Example 2
Input: {"tasks":["A","A","A","B","B","B"],"n":0}
Output: 6
Explanation: No cooldown needed.
Example 3
Input: {"tasks":["A"],"n":3}
Output: 1
Explanation: A single task.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →