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.
It’s important to note that during processing, instead of letting the wrong person move back, the focus should be on bringing the correct person forward. After each step of the iteration, the person in the current scanning position should be sorted.
For example, given [2 3 1 4 5]:
If '2' is moved back, the result will be:
[3 2 1 5 4]
This accidentally allows '3' to gain an additional bribe.
Been struggling with this for a while, hope this helps.
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 →
It’s important to note that during processing, instead of letting the wrong person move back, the focus should be on bringing the correct person forward. After each step of the iteration, the person in the current scanning position should be sorted.
For example, given [2 3 1 4 5]: If '2' is moved back, the result will be: [3 2 1 5 4]
This accidentally allows '3' to gain an additional bribe. Been struggling with this for a while, hope this helps.