We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4932eb5 commit c2c4b58Copy full SHA for c2c4b58
Interview Preparation Kit/Arrays/new-year-chaos/new-year-chaos.py
@@ -0,0 +1,30 @@
1
+from typing import List
2
+
3
4
+def minimumBribes(q: List[int]):
5
+ """
6
+ :param q: the positions of the people after all bribes
7
+ :return:No value is returned. Print the minimum number of bribes necessary or Too chaotic
8
+ if someone has bribed more than 2 people.
9
10
+ bribes = 0
11
12
+ for i in range(len(q)):
13
+ if q[i] - (i + 1) > 2:
14
+ print("Too chaotic")
15
+ return
16
17
+ for j in range(max(q[i] - 2, 0), i):
18
+ if q[j] > q[i]:
19
+ bribes += 1
20
21
+ print(bribes)
22
23
24
+if __name__ == '__main__':
25
+ t = int(input())
26
27
+ for t_itr in range(t):
28
+ n = int(input())
29
30
+ minimumBribes(list(map(int, input().rstrip().split())))
0 commit comments