forked from imabhinav-am/Competetive-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRainbowArray.cpp
More file actions
67 lines (66 loc) · 834 Bytes
/
RainbowArray.cpp
File metadata and controls
67 lines (66 loc) · 834 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
56
57
58
59
60
61
62
63
64
65
66
67
#include<iostream>
#include<algorithm>
using namespace std;
int seark(int arr[], int f, int l,int x)
{
int i;
for (i=f; i<l; i++)
if (arr[i] == x)
return i;
return -1;
}
int main()
{
int max,flag=1,ctr,k=0;
cin>>ctr;
char B[ctr];
do{
cin>>max;
int A[max];
for(int i=0;i<max;i++)
{
cin>>A[i];
}
int mid=(max-1)/2;
for(int j=0;j<mid;j++)
{
if(seark(A,mid,max,A[j])==-1)
{
flag=0;
break;
}
else if((seark(A,mid,max,A[j]))+j!=(max-1))
{
flag=0;
break;
}
}
if(flag==1)
{
if(A[mid]-A[mid-1]==1 && A[mid]-A[mid+1]==1)
{
B[k]='y';
k++;
}
else
{
B[k]='n';
k++;
}
}
else
{
B[k]='n';
k++;
}
ctr--;
}while(ctr!=0);
for(int l=0;l<k;l++)
{
if(B[l]=='y')
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
}
return 0;
}