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.
I like your first comment where the intuitive solution was just not efficient enough. So I figured that I didn't want to iterate over numbers that by coincidence landed on the correct location after a swap. So if I swapped the first array element arr[0] with element 5 arr[5] if arr[0] == 5+1, I can mark arr[5] as "ordered". That, and using a secondary array for storing the bolean, was enough to pass all the tests fast enough.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
I like your first comment where the intuitive solution was just not efficient enough. So I figured that I didn't want to iterate over numbers that by coincidence landed on the correct location after a swap. So if I swapped the first array element arr[0] with element 5 arr[5] if arr[0] == 5+1, I can mark arr[5] as "ordered". That, and using a secondary array for storing the bolean, was enough to pass all the tests fast enough.