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.
To solve it take care of the descending ones too. A counter case to show we also have to take the descending one.
Suppose if the array is-:
3 4 2 5 1
then the output should be 2.
5 4 2 3 1(swap 5 and 3)
5 4 3 2 1(swap 2 and 3)
Hence the answer will be 2.
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 →
To solve it take care of the descending ones too. A counter case to show we also have to take the descending one. Suppose if the array is-: 3 4 2 5 1 then the output should be 2. 5 4 2 3 1(swap 5 and 3) 5 4 3 2 1(swap 2 and 3) Hence the answer will be 2.