You are viewing a single comment's thread. Return to all comments →
Python code which passes all the test done in O(n). I think it is clean and easy to understand.
def minimumBribes(q): bribes = 0 ori = [x for x in range(1,len(q)+1)] i = 0 while i < len(q): if ori[i] == q[i]: next elif q[i] == ori[i+1]: ori[i+1], ori[i] = ori[i], ori[i+1] bribes +=1 elif q[i] == ori[i+2]: ori[i+2], ori[i+1] = ori[i+1], ori[i+2] ori[i+1], ori[i] = ori[i], ori[i+1] bribes +=2 else: print("Too chaotic") return i+=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 →
Python code which passes all the test done in O(n). I think it is clean and easy to understand.