Problem statement
Given a string and a number k, find the longest stretch that can be made into one repeated letter by replacing at most k of its letters.
The cells that change are the ones that are not the most common letter, so the window is allowed while its width minus its most common count stays within k.
Examples
Input"AABABBA", k = 1
Output4
Replacing the B at index 1 gives AAAA, a run of four.
Input"ABCDE", k = 1
Output2
Any two neighbouring letters differ in one cell, and three would need two changes.
The walkthrough is part of Premium
The statement and the examples above stay free. The full how-to-solve walkthrough, the cost notes in plain words and the interactive step-by-step visualizer unlock with a Premium plan.
See pricing