SDE Path

Task Scheduler with Cooldown

Medium

Task Scheduler with Cooldown

Given a list of tasks and a cooldown period, find the minimum time needed to complete all tasks.

Input format

The first line contains N and K. The second line contains N uppercase letters (A–F).

Output format

Print the minimum intervals to run all tasks with at least K gaps between same-letter tasks.

Constraints

  • Values fit in a 64-bit signed integer
  • Trailing whitespace and a trailing newline are ignored by the judge

Read from stdin, write to stdout. Sample cases below show the exact format.

Sample cases

Example 1
Input
6 2 AAABBB
Expected output
8
Example 2
Input
8 2 AAABBBCD
Expected output
8