java.lang.Object
g2301_2400.s2379_minimum_recolors_to_get_k_consecutive_black_blocks.Solution

public class Solution extends Object
2379 - Minimum Recolors to Get K Consecutive Black Blocks.<p>Easy</p> <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> <p>You are also given an integer <code>k</code>, which is the desired number of <strong>consecutive</strong> black blocks.</p> <p>In one operation, you can <strong>recolor</strong> a white block such that it becomes a black block.</p> <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> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> blocks = &ldquo;WBBWWBBWBW&rdquo;, k = 7</p> <p><strong>Output:</strong> 3</p> <p><strong>Explanation:</strong></p> <p>One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks so that blocks = &ldquo;BBBBBBBWBW&rdquo;.</p> <p>It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.</p> <p>Therefore, we return 3.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> blocks = &ldquo;WBWBBBW&rdquo;, k = 2</p> <p><strong>Output:</strong> 0</p> <p><strong>Explanation:</strong></p> <p>No changes need to be made, since 2 consecutive black blocks already exist.</p> <p>Therefore, we return 0.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == blocks.length</code></li> <li><code>1 <= n <= 100</code></li> <li><code>blocks[i]</code> is either <code>'W'</code> or <code>'B'</code>.</li> <li><code>1 <= k <= n</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • minimumRecolors

      public int minimumRecolors(String blocks, int k)