You are viewing a single comment's thread. Return to all comments →
C++
int minimumSwaps(vector arr) { int count = 0 ; int i = 0 ;
while(i<arr.size()) { if(arr[i] == i+1) i++; else { int t = arr[i]; arr[i] = arr[t-1]; arr[t-1] = t; count++; } } 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 →
C++
int minimumSwaps(vector arr) { int count = 0 ; int i = 0 ;
}