Description
Given a string blocks where W is white and B is black, and an integer k, find the minimum number of white blocks needed to recolor to get k consecutive black blocks.
Examples
Input:
blocks = "WBBWWBBWBW", k = 7Output:
3Explanation:
Recolor 3 W's.
Input:
blocks = "WBWBBBW", k = 2Output:
0Explanation:
The substring "BB" at positions 3-4 already contains 2 consecutive black blocks, so no recoloring is needed.
Input:
blocks = "BBBBWWWBBB", k = 5Output:
1Explanation:
5 consecutive black blocks are needed. The substring "BBBBW" (positions 0-4) has 4 B's and 1 W, so recoloring 1 W gives 5 consecutive B's.
Constraints
- •
1 ≤ blocks.length ≤ 100