You are viewing a single comment's thread. Return to all comments →
Java solution:
static int minimumSwaps(int[] arr) { int swaps = 0; for (int i = 0; i < arr.length; i++) { while (arr[i] != i + 1) { int temp = arr[arr[i] - 1]; arr[arr[i] - 1] = arr[i]; arr[i] = temp; swaps++; } } return swaps; }
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 →
Java solution: