Given a string `s` consisting of uppercase English letters and an integer `k`, you can choose any character in the string and change it to any other uppercase English letter at most `k` times. Return the length of the longest substring that contains only one repeating character after performing at most `k` replacements. For example, given s = "AABABBA" and k = 1, you can change one character. The longest substring of a single repeating character you can achieve is "AABAB**B**A" -> "AABABBA" -> change index 3 from 'B' to 'A' giving "AAAA" of length 4 (taking substring indices 0-3).
Example 1
Input: s = ABAB, k = 2
Output: 4
Explanation: With k = 2, replace both 'B's with 'A' to get "AAAA" (or both 'A's with 'B'). The whole string becomes one repeating character, length 4.
Example 2
Input: s = AABABBA, k = 1
Output: 4
Explanation: Take the substring "AABA" (indices 0-3) and change its single 'B' to 'A', giving "AAAA" of length 4. With only one change, no window of 5 can be made uniform.
Example 3
Input: s = AAAA, k = 2
Output: 4
Explanation: The string is already all 'A's, so its full length 4 counts without any changes.
Maintain a window [left, right] and track character frequencies inside it. The window is valid when (window_length - max_frequency) <= k, meaning we need at most k replacements. When invalid, shrink from the left.
Run checks all cases above. Submit evaluates all test cases.