Skip to content
Decoder

Minimum Recolors to Get K Consecutive Black Blocks

Easy

Problem

A row of blocks is described by the string blocks, where 'W' is white and 'B' is black. In one operation you can paint a white block black. Return the minimum number of operations needed so that there are `k` consecutive black blocks somewhere in the row.

Example 1

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

Example 2

Input
blocks = "WBWBBBW", k = 2
Output
0
Why
"BB" already exists

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.