2379. Minimum Recolors to Get K Consecutive Black Blocks
On This Page
class Solution:
def minimumRecolors(self, blocks: str, k: int) -> int:
res = cnt = blocks[:k].count('W')
for i in range(k, len(blocks)):
cnt += blocks[i] == 'W'
cnt -= blocks[i - k] == 'W'
res = min(res, cnt)
return res