class Solution(object):
def characterReplacement(self, s, k):
"""
:type s: str
:type k: int
:rtype: int
"""
p1, cnt = 0, [0] * 26
ans = 0
for p2 in range(len(s)):
cnt[ord(s[p2]) - ord('A')] += 1
while sum(cnt) - max(cnt) > k and p1 < p2:
cnt[ord(s[p1]) - ord('A')] -= 1
p1 += 1
if sum(cnt) - max(cnt) <= k:
ans = max(ans, p2 - p1 + 1)
return ans