Minimum Recolors to Get K Consecutive Black Blocks Problem
Minimum Recolors to Get K Consecutive Black Blocks Problem — ExecCode Easy DSA Practice
Solve the Minimum Recolors to Get K Consecutive Black Blocks problem on ExecCode. Free online easy DSA practice in String. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the i^th block. Your task is to compute the required answer and return the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks. The characters 'W' and 'B' denote the colors white and black, respectively. You are also given an integer k, which is the desired number of consecutive black blocks. In one operation, you can recolor a white block such that it becomes a black block.
Examples
Input {"blocks": "WBBWWBBWBW", "k": 7}; Output 3. Input {"blocks": "WBWBBBW", "k": 2}; Output 0
Constraints
n == blocks.length 1 <= n <= 100 blocks[i] is either 'W' or 'B'. 1 <= k <= n
Practice Minimum Recolors to Get K Consecutive Black Blocks free on ExecCode. Browse DSA problems, topic map, and placement guides.