A pixel-art editor shows a row of pixels as a string row of "B" (black) and "W" (white). The user wants k black pixels in a row somewhere and can recolor white pixels black, one at a time.
Write fewestRecolors(row, k) that returns the smallest number of white pixels that must be recolored so that some k consecutive pixels are all black. k is never more than row.length.
Input: row = "WBBWWBBWBW", k = 7 Output: 3
The 7 pixels from index 0 to 6, WBBWWBB, hold three whites. No window of 7 holds fewer.
Input: row = "WBWBBBW", k = 2 Output: 0
BB already exists.
1 <= k <= row.length <= 100000row contains only B and W.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #130 Fewest Recolors for a Solid Run. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.