forked from srgnk/HackerRank
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlarrys-array.py
More file actions
28 lines (23 loc) · 727 Bytes
/
larrys-array.py
File metadata and controls
28 lines (23 loc) · 727 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
#!/bin/python3
import sys
def rotate(A, pos):
A[pos], A[pos+1], A[pos+2] = A[pos+1], A[pos+2], A[pos]
def larrysArray(A):
for _ in range(len(A)):
for ind in range(1, len(A) - 1):
a, b, c = A[ind-1], A[ind], A[ind+1]
#print("ind = {} A = {} B = {} C = {}".format(ind, a, b, c))
if a > b or c < a:
#print("rotating 1")
rotate(A, ind-1)
if A == sorted(A):
return 'YES'
else:
return 'NO'
if __name__ == "__main__":
t = int(input().strip())
for a0 in range(t):
n = int(input().strip())
A = list(map(int, input().strip().split(' ')))
result = larrysArray(A)
print(result)