We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
defminimumBribes(q):# Write your code hereans=0L=len(q)fori,pinenumerate(reversed(q)):j=L-1-iifq[j-1]==j+1:q[j],q[j-1]=q[j-1],q[j]ans+=1elifq[j-2]==j+1:q[j],q[j-1],q[j-2]=q[j-2],q[j],q[j-1]ans+=2elifq[j]!=j+1:print('Toochaotic')returnprint(ans)
Cookie support is required to access HackerRank
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 →
Python3 solution: reverse bribe