We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d780968 commit f52f261Copy full SHA for f52f261
1 file changed
src/main/java/com/thealgorithms/leetcode/slidingwindow/alternatinggroupsII/Solution.java
@@ -0,0 +1,14 @@
1
+package com.thealgorithms.leetcode.slidingwindow.alternatinggroupsII;
2
+
3
+public class Solution {
4
+ public int numberOfAlternatingGroups(int[] colors, int k) {
5
+ int n = colors.length, res = 0, count = 1;
6
+ for (int i = 0; i < n + k - 2; i++) {
7
+ count = colors[i % n] != colors[(i + 1) % n] ? count + 1 : 1;
8
+ res += count >= k ? 1 : 0;
9
+ }
10
+ return res;
11
12
+}
13
14
+// https://leetcode.com/problems/alternating-groups-ii/?envType=daily-question&envId=2025-03-09
0 commit comments