AmazonOA #351
Task Scheduler
Estimated MediumJudge-ready
Each time slot either runs one task or stays idle, and all tasks can be reordered; two runs of tasks with the same letter must be separated by at least cooldown other slots. Find the minimum number of slots needed to finish everything.
Input
The first line contains the task string and the second line contains cooldown. Original bounds: 1..10000 tasks, letters A..Z, and 0≤cooldown≤100.
Output
Output a single integer, the answer.
Example 1
Input:
AAABBB
2
Output:
8
Example 2
Input:
ACABDB
1
Output:
6
Example 3
Input:
AAABBB
3
Output:
10
Example notes
The outputs of the three public examples are 8; 6; and 10, checked by independent enumeration or direct simulation.
Editorial
Loading solution…