Loading...
Loading...
You are given a string tasks of uppercase letters, where each character is one task, and an integer gap.
Each task takes exactly one unit of time. In every unit of time you either run one task or stay idle. The tasks can run in any order.
Between any two runs of the same letter, at least gap units of time must pass. Those units can run other tasks or stay idle.
Return the minimum number of units of time needed to run every task.
Input: tasks = "AAABBB", gap = 2
Output: 8
Explanation: One valid order is A B idle A B idle A B. Each repeated letter has two units between its runs.
Input: tasks = "AAABBB", gap = 0
Output: 6
Explanation: With no gap required, the six tasks run back to back.
Input: tasks = "AAAAAABCDEFG", gap = 2
Output: 16
Explanation: One valid order is A B C A D E A F G A idle idle A idle idle A. The six runs of A start at least 3 units apart, so the last one ends at unit 16.
tasks.length ≤104tasks[i] is an uppercase English lettergap ≤100