424. Longest Repeating Character Replacement
https://leetcode.com/problems/longest-repeating-character-replacement/
Python
class Solution:
def characterReplacement(self, s: str, k: int) -> int:
letters = set(s)
max_length = 0
for letter in letters:
left, count = 0, 0
for right in range(len(s)):
if s[right] == letter:
count += 1
# All letters which needs to be replaced can't large than k
# If its larger, move the left forward
while right-left+1 - count > k:
if s[left] == letter:
count -= 1
left += 1
max_length = max(max_length, right-left+1)
return max_length