Skip to content

Practice Minimum Recolors to Get K Consecutive Black Blocks

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Easy#2379
LeetCode Problem

Minimum Recolors to Get K Consecutive Black Blocks

Problem Statement

You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the ith block. 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. Return the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks.

Source: Minimum Recolors to Get K Consecutive Black Blocks on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
blocks = "WBBWWBBWBW", k = 7
Output
3

# Example 2

Input
blocks = "WBWBBBW", k = 2
Output
0

Constraints

n == blocks.length
1 <= n <= 100
blocks[i] is either 'W' or 'B'.
1 <= k <= n

Related LeetCode Problems

Practice more problems similar to Minimum Recolors to Get K Consecutive Black Blocks.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.