|
| 1 | +<p>You are given a <strong>0-indexed</strong> string <code>blocks</code> of length <code>n</code>, where <code>blocks[i]</code> is either <code>'W'</code> or <code>'B'</code>, representing the color of the <code>i<sup>th</sup></code> block. The characters <code>'W'</code> and <code>'B'</code> denote the colors white and black, respectively.</p> |
| 2 | + |
| 3 | +<p>You are also given an integer <code>k</code>, which is the desired number of <strong>consecutive</strong> black blocks.</p> |
| 4 | + |
| 5 | +<p>In one operation, you can <strong>recolor</strong> a white block such that it becomes a black block.</p> |
| 6 | + |
| 7 | +<p>Return<em> the <strong>minimum</strong> number of operations needed such that there is at least <strong>one</strong> occurrence of </em><code>k</code><em> consecutive black blocks.</em></p> |
| 8 | + |
| 9 | +<p> </p> |
| 10 | +<p><strong class="example">Example 1:</strong></p> |
| 11 | + |
| 12 | +<pre> |
| 13 | +<strong>Input:</strong> blocks = "WBBWWBBWBW", k = 7 |
| 14 | +<strong>Output:</strong> 3 |
| 15 | +<strong>Explanation:</strong> |
| 16 | +One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks |
| 17 | +so that blocks = "BBBBBBBWBW". |
| 18 | +It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations. |
| 19 | +Therefore, we return 3. |
| 20 | +</pre> |
| 21 | + |
| 22 | +<p><strong class="example">Example 2:</strong></p> |
| 23 | + |
| 24 | +<pre> |
| 25 | +<strong>Input:</strong> blocks = "WBWBBBW", k = 2 |
| 26 | +<strong>Output:</strong> 0 |
| 27 | +<strong>Explanation:</strong> |
| 28 | +No changes need to be made, since 2 consecutive black blocks already exist. |
| 29 | +Therefore, we return 0. |
| 30 | +</pre> |
| 31 | + |
| 32 | +<p> </p> |
| 33 | +<p><strong>Constraints:</strong></p> |
| 34 | + |
| 35 | +<ul> |
| 36 | + <li><code>n == blocks.length</code></li> |
| 37 | + <li><code>1 <= n <= 100</code></li> |
| 38 | + <li><code>blocks[i]</code> is either <code>'W'</code> or <code>'B'</code>.</li> |
| 39 | + <li><code>1 <= k <= n</code></li> |
| 40 | +</ul> |
0 commit comments