2379. Minimum Recolors to Get K Consecutive Black Blocks Easy
1/**
2 * [2379] Minimum Recolors to Get K Consecutive Black Blocks
3 *
4 * You are given a 0-indexed string blocks of length n, where blocks[i] is either 'W' or 'B', representing the color of the i^th block. The characters 'W' and 'B' denote the colors white and black, respectively.
5 * You are also given an integer k, which is the desired number of consecutive black blocks.
6 * In one operation, you can recolor a white block such that it becomes a black block.
7 * Return the minimum number of operations needed such that there is at least one occurrence of k consecutive black blocks.
8 *
9 * Example 1:
10 *
11 * Input: blocks = "WBBWWBBWBW", k = 7
12 * Output: 3
13 * Explanation:
14 * One way to achieve 7 consecutive black blocks is to recolor the 0th, 3rd, and 4th blocks
15 * so that blocks = "BBBBBBBWBW".
16 * It can be shown that there is no way to achieve 7 consecutive black blocks in less than 3 operations.
17 * Therefore, we return 3.
18 *
19 * Example 2:
20 *
21 * Input: blocks = "WBWBBBW", k = 2
22 * Output: 0
23 * Explanation:
24 * No changes need to be made, since 2 consecutive black blocks already exist.
25 * Therefore, we return 0.
26 *
27 *
28 * Constraints:
29 *
30 * n == blocks.length
31 * 1 <= n <= 100
32 * blocks[i] is either 'W' or 'B'.
33 * 1 <= k <= n
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/
39// discuss: https://leetcode.com/problems/minimum-recolors-to-get-k-consecutive-black-blocks/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn minimum_recolors(blocks: String, k: i32) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_2379() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.