Minimum Recolors to Get K Consecutive Black Blocks
EasySliding Window
Decode it first. Clues, constraints, pattern and plan before any code.A row of blocks is described by the string blocks, where 'W' is white and 'B' is black. In one operation you can paint a white block black. Return the minimum number of operations needed so that there are k consecutive black blocks somewhere in the row.
blocks = "WBBWWBBWBW", k = 7 → 3
blocks = "WBWBBBW", k = 2 → 0 ("BB" already exists)Constraints
1 <= k <= blocks.length <= 100blocks[i]is either'W'or'B'.