Given a string s of uppercase English letters and an integer k, you may choose at most k positions and overwrite each with any uppercase letter of your choice. Return the length of the longest substring that can be made into a single repeated letter after those changes.
You do not have to use all k changes.
Example 1
Input: s = "ABAB", k = 2
Output: 4
Change the two B's into A's (or the two A's into B's) to make the whole string uniform.
Example 2
Input: s = "AABABBA", k = 1
Output: 4
One change turns a window like "AABA" into "AAAA", giving a run of length four.
Constraints
1 <= s.length <= 10^50 <= k <= s.lengths consists of uppercase English letters only.See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.
FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.
750+ engineers trained · frontend, backend, AWS & AI