You are viewing a single comment's thread. Return to all comments →
Saw something. The statement says that the array consist of consecutive integers, but the first input sample says:
7 1 3 5 2 4 6 8
Whoa, was driving me nuts 'till I saw it :-)
By the way, the Test Case 14 is the same. Well, it's the only one, all the other passed with this solution:
var unsortedIndexes = new List<int>(); var swapSum = 0; for(int iterator = 0; iterator < arr.Length; iterator++){ while(arr[iterator] != iterator + 1){ var swapKey = arr[iterator] - 1; var temp = arr[iterator]; arr[iterator] = arr[swapKey]; arr[swapKey] = temp; swapSum++; } } return swapSum;
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 →
Saw something. The statement says that the array consist of consecutive integers, but the first input sample says:
Whoa, was driving me nuts 'till I saw it :-)
By the way, the Test Case 14 is the same. Well, it's the only one, all the other passed with this solution: