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):#Writeyourcodehere# q is an arr#q = q[::-1]sorted_q=sorted(q)total_count=0deffind_diff(q,target,idx):# this finds whats the idx of target in arr q# returns the diff of that and idx, if q < idx, ignore# if not, add diff to total countreturnq.index(target)-idxforiinrange(len(q)-1,-1,-1):ifsorted_q[i]==q[i]:continueelse:diff=-find_diff(q,sorted_q[i],i)ifdiff>2:print("Too chaotic")returnelifdiff>0:total_count+=diffprint(total_count)
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 →
This doesn't fully work