Skip to content

2379. Minimum Recolors to Get K Consecutive Black Blocks #1405

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the minimum number of operations required to convert a substring of length k in the given string blocks into consecutive black blocks ('B'). Each operation involves changing a white block ('W') to a black block.

Approach

  1. Sliding Window Technique: We will use a sliding window of length k to traverse the string blocks. This allows us to efficiently check each possible substring of length k.
  2. Count White Blocks: For each window, count the number of white blocks ('W'). The minimum number of white blocks in any window will be our answer, as each white block in the window needs to be recolored.

Let's implement this solution in PHP: 2379. Minimum Recolors to Get K Consecuti…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Mar 8, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Mar 8, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Mar 8, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested easy Difficulty
2 participants