Explanation:We can replace the two 'A's with 'B's or vice versa to obtain "BBBB" or "AAAA" of length 4.
Example 2:
Input:s = "AABABBA", k = 1
Output:4
Explanation:Replace the one 'A' in the middle with a 'B' to obtain "AABBBBA" then the longest substring of repeating characters is "BBBB" with the length of 4.
Example 3:
Input:s = "AAAA", k = 0
Output:4
Explanation:No replacements are needed, so the longest substring is the entire string "AAAA" with length 4.
Constraints:
•
•
•
Time Complexity
O(n)
Space Complexity
O(1)
Step 1 / 46
Speed: 1.0x
Input String: "AABABBA" (k=1)
A
l
A
B
A
B
B
A
Process Step
Initialize variables: l = 0, res = 0, count = {}, maxf = 0.