-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLarry's Array
More file actions
39 lines (24 loc) · 762 Bytes
/
Larry's Array
File metadata and controls
39 lines (24 loc) · 762 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
def is_odd(number):
return number % 2
def count_inversion(index, numbers):
inversion_count = 0
i = index - 1
while i >= 0:
if numbers[i] > numbers[index]:
inversion_count += 1
i -= 1
return inversion_count
def larrysArray(numbers):
inversion_count = 0
for i in range(len(numbers)):
inversion_count += count_inversion(i, numbers)
return "NO" if is_odd(inversion_count) else "YES"
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
t = int(input().strip())
for t_itr in range(t):
n = int(input().strip())
A = list(map(int, input().rstrip().split()))
result = larrysArray(A)
fptr.write(result + '\n')
fptr.close()