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.
The key appears to be that the map is created prior to the sorting, so it indeed is different for the two passes and results in the swaps being done in a different order.
Specifically i in the first for loop is different for the two passes.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Lily's Homework
You are viewing a single comment's thread. Return to all comments →
The key appears to be that the map is created prior to the sorting, so it indeed is different for the two passes and results in the swaps being done in a different order.
Specifically
i
in the firstfor
loop is different for the two passes.