2379. Minimum Recolors to Get K Consecutive Black Blocks

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2379

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