Tap here to switch tabs
Problem
Submissions

Problem: Minimum Recolors to Get K Consecutive Black Blocks

med
30 min
Try to solve the Minimum Recolors to Get K Consecutive Black Blocks problem.

Statement

You are given a 00 indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the iith block. The characters 'W' and 'B' denote the colors white and black, respectively.

You are also given an integer k, which represents the desired number of consecutive black blocks.

In one operation, you can recolor a white block to become a black block.

Return the minimum number of operations required so that there is at least one sequence of k consecutive black blocks.

Constraints:

  • n == blocks.length

  • 1≤1 \leq n ≤100\leq 100

  • blocks[i] is either 'W' or 'B'.

  • 1≤1 \leq k ≤\leq n

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Recolors to Get K Consecutive Black Blocks

med
30 min
Try to solve the Minimum Recolors to Get K Consecutive Black Blocks problem.

Statement

You are given a 00 indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the iith block. The characters 'W' and 'B' denote the colors white and black, respectively.

You are also given an integer k, which represents the desired number of consecutive black blocks.

In one operation, you can recolor a white block to become a black block.

Return the minimum number of operations required so that there is at least one sequence of k consecutive black blocks.

Constraints:

  • n == blocks.length

  • 1≤1 \leq n ≤100\leq 100

  • blocks[i] is either 'W' or 'B'.

  • 1≤1 \leq k ≤\leq n