← 返回 scale.ai 的题目列表Task Scheduling
类型:online_judge
Task Scheduling
Given an array of tasks represented by uppercase English letters, where each letter denotes a task type, and a non-negative integer n representing a cooldown interval between two executions of the same task type.
During each unit of time, the CPU can execute at most one task or remain idle. Tasks may be executed in any order.
Return the minimum number of time units required to finish all tasks.
Input Format
Line 1: a whitespace-free string tasks of uppercase letters
Line 2: integer n
Output Format
Print one integer: the minimum time needed to finish all tasks.
Example 1
Input:
AAABBB
2
Output:
8
One valid schedule is: A -> B -> idle -> A -> B -> idle -> A -> B.
Example 2
Input:
AAABBB
0
Output:
6
Constraints
1 <= len(tasks) <= 10^4
tasks contains only uppercase letters from A to Z
0 <= n <= 100
Example
Input
AAABBB
2
Output
8