Longest Repeating Character Replacement
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
index = defaultdict(int)
start = 0
end = 0
res = 0
cur_max = 0
for end in range(len(s)):
index[s[end]] += 1
cur_max = max(cur_max, index[s[end]])
while (end - start + 1) - cur_max > k:
index[s[start]] -= 1
start += 1
res = max(res, end - start + 1)
return resLast updated