Longest Repeating Character Replacement
You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English letter. You can perform this operation at most k times. Return the length of the longest substring containing the same letter you can get after performing the above operations.
Longest Repeating Character Replacement
You are given a string s and an integer k. You can choose any character of the string and change it to any other uppercase English letter. You can perform this operation at most k times. Return the length of the longest substring containing the same letter you can get after performing the above operations.
Example 1
Input: s = "ABAB", k = 2 Output: 4
Example 2
Input: s = "AABABBA", k = 1 Output: 4
Show hint
Use sliding window. Track frequency of each character. Window is valid if (window_length - max_frequency) <= k. Expand right, shrink left when invalid.
Sign in to submit, save progress and mark problems as solved. You can still run your code.
Loading editor...
"ABAB"
2
4