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:
Sliding window of size 7: the window with minimum W's is 'WBBWBW' with 3 whites. Recolor those 3 to get 7 consecutive blacks.
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:
The best length-5 window has exactly 1 white block, so recoloring that one block gives 5 consecutive black blocks. The exact output is 1.
Constraints
- •
1 ≤ blocks.length ≤ 100