Loading...
Loading...
Loading...
A worker has a list of tasks, each named by a capital letter. One task is done per time slot, or the worker waits. Two tasks with the same letter must have at least c slots between them. Print the least number of slots needed to finish all tasks.
Example 1
Input
AAABBB 2
Output
8
Example 2
Input
AAABBB 0
Output
6
Try the problem first. Open one hint at a time.
The most frequent letter decides the shape of the schedule.
Count the letters with the maximum frequency m. The answer is the larger of the task count and (m - 1) * (c + 1) + the number of letters that have frequency m.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor