Skip to content

Commit 16aafb2

Browse files
2379_Minimum_Recolors_to_get_K_consecutive_Black_Blocks.java
1 parent 933d95a commit 16aafb2

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Problem Number: 2379
2+
3+
// Minimum Recolors to get K consecutive black blocks.
4+
5+
class Solution {
6+
public int minimumRecolors(String blocks, int k) {
7+
int blackCount = 0, ans = Integer.MAX_VALUE;
8+
9+
for (int i = 0; i < blocks.length(); i++) {
10+
if (i - k >= 0 && blocks.charAt(i - k) == 'B') blackCount--;
11+
if (blocks.charAt(i) == 'B') blackCount++;
12+
ans = Math.min(ans, k - blackCount);
13+
}
14+
15+
return ans;
16+
}
17+
}

0 commit comments

Comments
 (0)