Skip to content

Commit 1c08387

Browse files
committed
📝 upload 2379th README
1 parent d95f44b commit 1c08387

File tree

1 file changed

+45
-0
lines changed
  • LeetCode/2379. Minimum Recolors to Get K Consecutive Black Blocks

1 file changed

+45
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# [2379. Minimum Recolors to Get K Consecutive Black Blocks](https://leetcode.cn/problems/minimum-recolors-to-get-k-consecutive-black-blocks/description/)
2+
3+
![](https://img.shields.io/badge/Difficulty-Easy-green.svg)
4+
5+
<details>
6+
<summary>Topics</summary>
7+
8+
* [`String`](https://leetcode.com/tag/string/)
9+
* [`Sliding Window`](https://leetcode.com/tag/sliding-window/)
10+
11+
</details>
12+
<br />
13+
14+
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.
15+
16+
You are also given an integer `k`, which is the desired number of **consecutive** black blocks.
17+
18+
In one operation, you can **recolor** a white block such that it becomes a black block.
19+
20+
Return *the **minimum** number of operations needed such that there is at least **one** occurrence of `k` consecutive black blocks*.
21+
22+
**Example 1:**
23+
24+
Input: blocks = "WBBWWBBWBW", k = 7
25+
Output: 3
26+
Explanation:
27+
One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks
28+
so that blocks = "BBBBBBBWBW".
29+
It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.
30+
Therefore, we return 3.
31+
32+
**Example 2:**
33+
34+
Input: blocks = "WBWBBBW", k = 2
35+
Output: 0
36+
Explanation:
37+
No changes need to be made, since 2 consecutive black blocks already exist.
38+
Therefore, we return 0.
39+
40+
**Constraints:**
41+
42+
+ `n == blocks.length`
43+
+ `1 <= n <= 100`
44+
+ `blocks[i]` is either `'W'` or `'B'`.
45+
+ `1 <= k <= n`

0 commit comments

Comments
 (0)