We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 771c1fb commit 6e32c3cCopy full SHA for 6e32c3c
problem-of-the-day/March/09_alternatingGroups.cpp
@@ -0,0 +1,31 @@
1
+class Solution {
2
+public:
3
+ int numberOfAlternatingGroups(vector<int>& colors, int k) {
4
+ int n = colors.size();
5
+ for(int i = 0; i < k-1; i++){
6
+ colors.push_back(colors[i]);
7
+ }
8
+
9
+ // new array
10
+ int N = n + (k - 1);
11
+ int i = 0, j = 1;
12
13
+ int result = 0;
14
+ while(j < N){
15
+ if(colors[j] == colors[j-1]){
16
+ i = j;
17
+ j++;
18
+ continue;
19
20
21
+ if(j - i + 1 == k){
22
+ result += 1;
23
+ i++;
24
25
26
27
28
29
+ return result;
30
31
+};
0 commit comments