- Should have thought of
sliding window. (It targets most likely for
- Why? Because between a certain length of
substr, there are some repetitive chars and other chars that can be replaced. It just sounds like a sliding window question.
- Use a generic sliding window template to solve this.
- Use an array to store the number of each char.
right - left + 1 - Math.max(...alphabets) > k, it means even if we exhaust all
ks, there will still be extra chars. So we need to move
- At the end, update
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 character. You can perform this operation at most
Return the length of the longest substring containing the same letter you can get after performing the above operations.
Input: s = "AABABBA", k = 1