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.
Example 1:
Solution
The idea here is to keep a hashmap of frequencies for each character. We use a sliding window and update our hashmap accordingly. If we have:
then we for that window, we can get a a string with just one letter.