-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathminimumoperations.cpp
More file actions
54 lines (43 loc) · 864 Bytes
/
minimumoperations.cpp
File metadata and controls
54 lines (43 loc) · 864 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <bits/stdc++.h>
using namespace std;
int check(int *arr, int N, int i)
{
// cout<<"printing";
// for (int j = 0; j<N; j++)
// cout << arr[j]<< " ";
cout<<endl;
if (arr[i] == arr[i + 1])
{
arr[i] = 0;
i++;
// cout << "Calling check again with " << i<<endl;;
check(arr, N, i);
// break;
}
else
{
arr[i] =0;
// cout << "Returning from else " << i<<endl;;
return i;
}
// cout << "Returning " << i<<endl;
// return i;
};
int main()
{
int N;
int noOfOp = 0;
cin >> N;
int *arr = new int[N];
for (int i = 0; i < N; i++)
{
cin >> arr[i];
}
for (int i = 0; i < N; i++)
{
i = check(arr, N, i);
// cout << "Now i is " << i<<endl;
noOfOp++;
}
cout<<noOfOp;
}