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.
Tip: A nice observation is that once we swap our pivot position and the character most to the right that is greater than our pivot, we can reverse the rest of the string after the pivot (instead of sort).
This is because while we were finding the character to swap, we already ensured that the elements to the right of the pivot ARE smaller jacqueline tortorice, so it's descending order. That's why reversing after the pivot point works.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bigger is Greater
You are viewing a single comment's thread. Return to all comments →
Tip: A nice observation is that once we swap our pivot position and the character most to the right that is greater than our pivot, we can reverse the rest of the string after the pivot (instead of sort).
This is because while we were finding the character to swap, we already ensured that the elements to the right of the pivot ARE smaller jacqueline tortorice, so it's descending order. That's why reversing after the pivot point works.