-
Notifications
You must be signed in to change notification settings - Fork 0
/
new-year-chaos.py
41 lines (30 loc) · 999 Bytes
/
new-year-chaos.py
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
# Solution for the problem "New Year Chaos"
# https://www.hackerrank.com/challenges/new-year-chaos/problem
t = int(input())
for i in range(0, t):
n = int(input())
positions = list(map(int, input().strip().split(' ')))
gone_ahead = 0
chaotic = False
for index in range (0, n - 1):
num = positions[index]
diff = num - index - 1
if diff > 2:
chaotic = True
break
num_a = positions[index + 1]
if num > num_a:
gone_ahead += 1
positions[index], positions[index + 1] = num_a, num
if chaotic:
print("Too chaotic")
continue
for index in range (n - 2, -1, -1):
for index2 in range (0, index):
num = positions[index2]
diff = num - index2 - 1
num_a = positions[index2 + 1]
if num > num_a:
gone_ahead += 1
positions[index2], positions[index2 + 1] = num_a, num
print(gone_ahead)