forked from coder2hacker/Explore-open-source
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPairwise Consecutive Elements.cpp
More file actions
55 lines (49 loc) · 963 Bytes
/
Pairwise Consecutive Elements.cpp
File metadata and controls
55 lines (49 loc) · 963 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
55
#include <bits/stdc++.h>
using namespace std;
bool pairWiseConsecutive(stack<int> s);
// Driver program
int main()
{
int t;
cin>>t;
while(t--)
{
stack<int> s;
int n, tmp;
cin>>n;
while(n--){
cin>>tmp;
s.push(tmp);
}
if (pairWiseConsecutive(s))cout << "Yes" << endl;
else cout << "No" << endl;
/*while (s.empty() == false)
{
cout << s.top() << " ";
s.pop();
}
cout<<endl;*/
}
return 0;
}
// } Driver Code Ends
//User function Template for C++
// your task is to complete the function
// function should return true/false or 1/0
bool pairWiseConsecutive(stack<int> s)
{
//Code here
stack<int> s1;
if(s.size()%2)
s.pop();
while(!s.empty())
{
int a=s.top();
s.pop();
int b=s.top();
s.pop();
if(abs(a-b)!=1)
return 0;
}
return 1;
}