401. Task Scheduler
MediumGreedyCounting
Tasks are letters; each takes one unit of time. The same task must be separated by at least n units (idle slots allowed). Print the minimum total time.
Input format
Line 1: the tasks (uppercase letters, no spaces) Line 2: n
Output format
The minimum time.
Example 1
Input
AAABBB 2
Output
8
Example 2
Input
AAABBB 0
Output
6
Constraints
1 ≤ tasks ≤ 10⁴ 0 ≤ n ≤ 100
Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.
Loading the MyLoginn IDE…