You are viewing a single comment's thread. Return to all comments →
This works ( in py)
def minimumBribes(q): # Write your code here n = len(q) total = 0 sorted_q = list(range(1, n + 1)) for i in range (n): if q[i] == sorted_q[i]: continue elif q[i] == sorted_q[i + 1]: sorted_q[i], sorted_q[i + 1] = sorted_q[i + 1], sorted_q[i] total += 1 elif q[i] == sorted_q[i + 2]: sorted_q[i + 1], sorted_q[i + 2] = sorted_q[i + 2], sorted_q[i + 1] sorted_q[i], sorted_q[i + 1] = sorted_q[i + 1], sorted_q[i] total += 2 else: print("Too chaotic") return print(total) return
Seems like cookies are disabled on this browser, please enable them to open this website
New Year Chaos
You are viewing a single comment's thread. Return to all comments →
This works ( in py)