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.
This approach is mostly about the fact that we only need to count all people in front of us (who could bribe the current person and not more than two bigger than us)
def minimumBribes(q):
bribes = 0
for i in range(len(q)):
if q[i] - (i + 1) > 2:
print("Too chaotic")
return
for j in range(max(0, q[i] - 2), i):
if q[j] > q[i]:
bribes += 1
print(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 →
This approach is mostly about the fact that we only need to count all people in front of us (who could bribe the current person and not more than two bigger than us) def minimumBribes(q): bribes = 0