You are viewing a single comment's thread. Return to all comments →
This code solves all the test cases , even if it contains consecutive integers
int minimumSwaps(vector<int> arr) { int len = arr.size(); int count = 0; for(int i = 0;i<len;i++) { if(arr[i] != i+1 && arr[i]<=len) { swap(arr[i],arr[arr[i]-1]); count++; i--; } } return count; }
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 →
This code solves all the test cases , even if it contains consecutive integers