106. Longest Repeating Character Replacement
Given an integer k and a string s, any character in the string can be selected and changed to any other uppercase English character. This operation can be performed up to k times. After completing these steps, return the length of the longest substring that contains the same letter.
Example 1:
Input : s = "BAABAABBBAAA" , k = 2
Output : 6
Explanation : we can change the B present at index 0 , 3 (0 base indexing) to A.
The new string is "AAAAAABBBAAA".
The substring "AAAAAA" is the longest substring having same letter with length 6.
Example 2:
Input : s = "AABABBA" , k = 1
Output : 4
Explanation : The underlined characters are changed in the new string obtained.
The new string is "AABBBBA". The substring "BBBB" is the answer.
There are other ways to achieve this answer.
Now Your Turn!
Pick the correct output for the given inputInput : s = "ABCDEF" k = 1
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= s.length <= 105
- 0 <= k <= s.length
- s contains only English uppercase letters.