1def character_replacement(s, k):
2 counts = {}
3 max_count = 0
4 left = 0
5 max_len = 0
6 for right in range(len(s)):
7 counts[s[right]] = counts.get(s[right], 0) + 1
8 max_count = max(max_count, counts[s[right]])
9 while (right - left + 1) - max_count > k:
10 counts[s[left]] -= 1
11 left += 1
12 max_len = max(max_len, right - left + 1)
13 return max_len