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(arr:list)->None:"""Count bribes from the perspective of the person being overtaken."""bribes=0fori,stickerinenumerate(arr):pos=i+1#queuepositionis1-indexed# check for 2+ bribes:ifsticker-pos>2:print("Too chaotic")return# for each person, count no. of overtakes# only have to check previous two positions:forjinrange(max(0,sticker-2),i):#noti-2ifarr[j]>sticker:bribes+=1print(bribes)
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 →
Python solution: