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.
why should we start checking from the end of the queue while calculating the bribes. whats is wrong if we compare the array index +1 with the element calculate the difference from the starting of the queue?
what is logically wrong with the below approach? can someone help me understand?
for i in range(len(q)):
if i+1 < q[1]:
calculate the difference between the index and the actual element;
if the difference is above two, we return too chaotic and exit loop.
elif the difference is 2 then add two to a counter, else add 1
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 →
why should we start checking from the end of the queue while calculating the bribes. whats is wrong if we compare the array index +1 with the element calculate the difference from the starting of the queue?
what is logically wrong with the below approach? can someone help me understand? for i in range(len(q)): if i+1 < q[1]: calculate the difference between the index and the actual element; if the difference is above two, we return too chaotic and exit loop. elif the difference is 2 then add two to a counter, else add 1