Skip to content

Commit c2c4b58

Browse files
committed
If I'm not back in five minutes, just wait longer.
1 parent 4932eb5 commit c2c4b58

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)