Ctrl K

Repaint for a Dark Stretch

Easy
The tiles of a path are given by the string tiles: 'B' is a black tile and 'W' is a white one. One operation repaints any white tile black. What is the minimum number of operations needed so that the path contains run black tiles in a row somewhere?
Example 1
tiles="BWBBWWB", run=4 → 1

The stretch "BWBB" has one white tile; repaint it and you have four black tiles in a row.

Example 2
tiles="WWBW", run=1 → 0

There is already a black tile, so nothing needs repainting.

Example 3
tiles="WWW", run=3 → 3
Constraints
  • 1 ≤ len(tiles) ≤ 100
  • Every character of tiles is 'W' or 'B'
  • 1 ≤ run ≤ len(tiles)
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsBoth Cases Stretch EasyTriples Without Repeats EasyDigit Windows That Divide EasyEach Letter At Most Twice EasyFew Zeros or Few Ones Easy
loading Python…
Input
tiles="BWBBWWB", run=4
Expected
1

Run checks the first 3 tests in your browser. Submit checks all 104 tests on the server, hidden ones included.