Longest Repeating Character Replacement
Given a string s consisting of uppercase English letters and an integer k, you can replace at most k characters in the string with any uppercase English letter.
Return the length of the longest substring containing the same character after performing at most k replacements.
Example 1
Input
ABAB 2
Output
4
Explanation
Replace both A characters with B, or both B characters with A, to make the entire string identical.
Example 2
Input
AABABBA 1
Output
4
Explanation
By replacing one character, a longest valid substring such as AABA can be made entirely of A characters.
Constraints
Hints:
Hint 1
Use a sliding window to maintain a substring that can be made identical using at most k replacements.
Hint 2
Track the most frequent character in the current window. The number of replacements required is the window length minus that character's frequency.
Author & Technical Reviewer
Content Verification Methodology
Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.
Expected Output