You are viewing a single comment's thread. Return to all comments →
But it returns a "wrong" output of "2" for the non consecutive test case:
4 5 10 2 1
4
5 10 2 1
The resulting array would be 1 2 10 5 which needs another swap to be sorted, so the right result would be "3".
I think there is no algorithm that solves non consecutive test cases like the above one and all the other test cases.
Skipping the 8 in Test Case 2:
7 1 3 5 2 4 6 8
7
1 3 5 2 4 6 8
only works because 8 is on the correct position already.
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 →
But it returns a "wrong" output of "2" for the non consecutive test case:
The resulting array would be 1 2 10 5 which needs another swap to be sorted, so the right result would be "3".
I think there is no algorithm that solves non consecutive test cases like the above one and all the other test cases.
Skipping the 8 in Test Case 2:
only works because 8 is on the correct position already.