Loading...
You are given a string s whose characters are each either 'W' or 'B', and an integer k.
In one change you may rewrite a single 'W' into a 'B'. You may not rewrite a 'B'.
Return the minimum number of changes needed so that s contains at least one run of k consecutive 'B' characters.
Input: s = "WBBWWBBWBW", k = 7
Output: 3
Explanation: The window covering indices 0..6 is "WBBWWBB" and holds three 'W'
characters, at indices 0, 3 and 4. Changing those three gives "BBBBBBBWBW",
which contains a run of 7 consecutive 'B'. No window of length 7 holds fewer
than three 'W', so 3 changes are necessary.
Input: s = "WBWBBBW", k = 2
Output: 0
Explanation: The window covering indices 3..4 is already "BB", so a run of 2
consecutive 'B' exists and no change is needed.
s.length ≤100s[i] is either 'W' or 'B'.s.lengthClick "Run" to test with sample cases or "Submit" to run all tests.