You are viewing a single comment's thread. Return to all comments →
def minimumBribes(q): # Write your code here n = len(q) bribes = 0 ref = list(range(1, n+1)) for i in range(n-1): if q[i] != ref[i]: # Swap ref[i], ref[i+1] = ref[i+1], ref[i] if q[i] != ref[i]: #Reswap ref[i], ref[i+2] = ref[i+2], ref[i] if q[i] == ref[i]: bribes += 2 else: print('Too chaotic') return else: bribes += 1 print(bribes) 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 →