-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLarrys_Array.cpp
More file actions
48 lines (36 loc) · 847 Bytes
/
Larrys_Array.cpp
File metadata and controls
48 lines (36 loc) · 847 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
//Problem: https://www.hackerrank.com/challenges/larrys-array/problem
// 15 tile invariant: https://www.cs.bham.ac.uk/~mdr/teaching/modules04/java2/TilesSolvability.html
// Editorial: https://www.hackerrank.com/challenges/larrys-array/editorial
#include <bits/stdc++.h>
using namespace std;
string larrysArray(vector<int> A)
{
int n = A.size();
int cnt = 0;
for(int i = 0; i < n-1; i++)
{
for(int j = i+1; j < n; j++)
{
if(A[i] > A[j])
cnt++;
}
}
if(cnt % 2 == 0)
return "YES";
return "NO";
}
int main()
{
int t;
cin >> t;
while(t--)
{
int n;
cin >> n;
vector <int> A(n);
for(int i = 0; i < n; i++)
cin >> A[i];
cout << larrysArray(A) << endl;
}
return 0;
}