Skip to content

Commit

Permalink
Create 2379. Minimum Recolors to Get K Consecutive Black Blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
Chayandas07 authored Mar 8, 2025
1 parent 9cdedd3 commit 06410ac
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 2379. Minimum Recolors to Get K Consecutive Black Blocks
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution {
public:
int minimumRecolors(string s, int k) {
const int n = s.size();
// if (k > n) return -1;
int w = 0;
for (int i = 0; i < k; ++i)
w += s[i] == 'W';
int minw = w;
for (int i = k; i < n; ++i) {
w += s[i] == 'W';
w -= s[i - k] == 'W';
minw = min(minw, w);
// if (minw == 0) return 0;
}
return minw;
}
};

0 comments on commit 06410ac

Please sign in to comment.