Longest Repeat With k Changes
You are given a string text of capital letters A–Z and a number k. You may change at most k letters of the text, each into any other capital letter. Return the length of the longest run of one repeated letter you can make.
Examples
text = "ABAB", k = 2 → 4
text = "AABABBA", k = 1 → 4
text = "ABCDE", k = 0 → 1
text = "AAAA", k = 2 → 4In the first example, changing both Bs gives "AAAA". In the second, changing the A at index 3 gives "AABBBBA", with four Bs in a row. With k = 0 nothing can change, so the answer is the longest run already there.
Constraints
- Between 0 and 20,000 letters;
kis between 0 and 20,000. - Aim for O(n): there are 26 letters, so counting them is a fixed amount of work per step.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.