forked from srishilesh/Data-Structure-and-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNewyear_chaos
40 lines (31 loc) · 851 Bytes
/
Newyear_chaos
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
// https://www.hackerrank.com/challenges/new-year-chaos/problem
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the minimumBribes function below.
def minimumBribes(q):
count = 0
# for i in range(len(q)):
f = 0
for i in range(len(q)):
#for j in range(0, len(q)-i-1):
if((q[i]-(i+1))>2):
print("Too chaotic")
return
# if q[j] > q[j+1] :
# q[j], q[j+1] = q[j+1], q[j]
# count+=1
for j in range(max(q[i]-2,0),i):
if q[j]-1 > q[i]-1:
count+=1
if(f==0):
print(count)
if __name__ == '__main__':
t = int(input())
for t_itr in range(t):
n = int(input())
q = list(map(int, input().rstrip().split()))
minimumBribes(q)