Problem Overview
The "Longest Repeating Character Replacement" problem (LeetCode 424) asks you to find the longest substring in a given string where you can replace at most k characters to make all characters identical. This is a Microsoft interview favorite tagged with String, Hash Table, and Sliding Window.[1][9]
Full Problem Statement
You are given a string s consisting of uppercase English letters and an integer k. You can choose any character of the string and change it to any other uppercase English letter at most k times in total. Return the length of the longest substring containing the same letter you can get after performing the above operations.[9][1]
Input/Output Examples
Here are the standard examples from LeetCode and solution sites:
| Example | Input | Output | Explanation | |---------|-------|--------|-------------| | 1 | s = "ABAB", k = 2 | 4 | Replace two 'A's with 'B's (or vice versa) to get "BBBB" or "AAAA".[1][2] | | 2 | s = "AABABBA", k = 1 | 4 | Replace the middle 'A' with 'B' to get "AABBBBA"; substring "BBBB" has length 4.[2][3] | | 3 | s = "ABBABBBA", k = 2 | 5 | Replace first 'A' and one other to form a length-5 run like "BBBBB".[3] |
Constraints