forked from Sam071100/CodeForces-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpseudosort.cpp
More file actions
42 lines (40 loc) · 670 Bytes
/
pseudosort.cpp
File metadata and controls
42 lines (40 loc) · 670 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
//Solution to Pseudo Sorted Array on codechef
#include <iostream>
using namespace std;
int main() {
int t;
cin>>t;
while(t-->0)
{
int n;
cin>>n;
long long int ar[n];
for(int x=0;x<n;x++)
{
cin>>ar[x];
}
for(int x=0;x<n-1;x++)
{
if(ar[x]>ar[x+1])
{
int t=ar[x];
ar[x]=ar[x+1];
ar[x+1]=t;
break;
}
}
int f=0;
for(int x=0;x<n-1;x++)
{
if(ar[x]>ar[x+1])
{
cout<<"No"<<endl;
f=1;
break;
}
}
if(f==0)
cout<<"Yes"<<endl;
}
return 0;
}