Sliding Window
50. Longest Repeating Character Replacement
You are given a string s and an integer k. You can choose any character in the string and change it to any other uppercase English letter. You may perform this operation at most k times.
Return the length of the longest substring containing the same letter that you can obtain after performing the operations.
Examples
Example 1
Input: s = "ABAB", k = 2
Output: 4
Explanation: Replace the two 'A' characters with 'B' (or vice versa) to get a substring of length 4 with the same letter.
Example 2
Input: s = "AABABBA", k = 1
Output: 4
Explanation: Replace the 'A' in the middle with 'B' to form "AABBBBA". The substring "BBBB" has length 4, which is the maximum.
Constraints
1 <= s.length <= 10^5sconsists of only uppercase English letters.0 <= k <= s.length
Keyboard shortcuts
← h Previous problem
→ l Next problem
Esc Back to index
? Toggle this help