Skip to content

Commit b7c6b40

Browse files
authored
Merge pull request SjxSubham#247 from DrDread746/temp
3208. Alternating Groups II
2 parents 1906101 + 8e6531f commit b7c6b40

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

3208.Alternating Groups II.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class Solution {
2+
public:
3+
int numberOfAlternatingGroups(vector<int>& colors, int k) {
4+
int n = colors.size();
5+
vector<int> arr(2 * n);
6+
copy(colors.begin(), colors.end(), arr.begin());
7+
copy(colors.begin(), colors.end(), arr.begin() + n);
8+
int l = 0, r = 1, flag = colors[0], count = 0;
9+
while (r < arr.size() && l < n) {
10+
if (arr[r] == flag) l = r;
11+
else flag = arr[r];
12+
if ((r - l + 1) == k) {
13+
count++;
14+
l++;
15+
}
16+
r++;
17+
}
18+
return count;
19+
}
20+
};

0 commit comments

Comments
 (0)