Back to DSA
Longest Repeating Character Replacement
mediumA string of uppercase English letters and an integer k are given. You may change up to k characters in the string to any other uppercase letter. After making at most k replacements, what is the length of the longest substring where every character is the same?
Examples
Example 1:
Input:
s = "XYXY", k = 1Output:
3Explanation: Change one 'Y' to 'X' (or vice versa) to obtain a run of three identical characters, e.g., 'XXX' within 'XXXY'.
Example 2:
Input:
s = "AABABBA", k = 2Output:
5Explanation: Replace two B's to get 'AAAAABA' or similar. The longest uniform segment is 5.
Hints
1234567