From 06410ac190bff8ab3aa9c4d70b7609cd812c82f9 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sat, 8 Mar 2025 23:53:07 +0530 Subject: [PATCH] Create 2379. Minimum Recolors to Get K Consecutive Black Blocks --- ... Recolors to Get K Consecutive Black Blocks | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 2379. Minimum Recolors to Get K Consecutive Black Blocks diff --git a/2379. Minimum Recolors to Get K Consecutive Black Blocks b/2379. Minimum Recolors to Get K Consecutive Black Blocks new file mode 100644 index 0000000..439425b --- /dev/null +++ b/2379. Minimum Recolors to Get K Consecutive Black Blocks @@ -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; + } +};