Question
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Âk
 times.Return the length of the longest substring containing the same letter you can get after performing the above operations.
This is asliding_window question.
Idea
- Use a sliding window (use an L and R pointer that start at position 0) (While R < len(s))
- Use a hashmap to keep track of the characters that we’ve seen
- Check if the current sliding window size - count of the most frequent character ≤ k
- If true:
- update res
- Else: Reduce count at [L] Slide L
- Slide R
- If true:
- Return res