From d92587cd75cc9d148874a536cbb2373da8b11488 Mon Sep 17 00:00:00 2001 From: chayan das <110921638+Chayandas07@users.noreply.github.com> Date: Sun, 9 Mar 2025 23:39:28 +0530 Subject: [PATCH] Create 3208. Alternating Groups II --- 3208. Alternating Groups II | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 3208. Alternating Groups II diff --git a/3208. Alternating Groups II b/3208. Alternating Groups II new file mode 100644 index 0000000..8a4e404 --- /dev/null +++ b/3208. Alternating Groups II @@ -0,0 +1,14 @@ +class Solution { +public: + int numberOfAlternatingGroups(vector& colors, int k) { + int ans = 0, cnt = 1, n = colors.size(); + for(int i = 1; i < (n + k - 1); i++) { + if(colors[i % n] != colors[(i - 1) % n]) { + cnt++; + } + else cnt = 1; + if(cnt >= k) ans++; + } + return ans; + } +};