You are viewing a single comment's thread. Return to all comments →
// Complete the minimumSwaps function below. static int minimumSwaps(int[] arr) { int count = 0; int diff = 0; int temp = 0; for(int i=0; i<arr.Length; i++){ if(arr[i] != i+1){ diff = arr[i] - 1; temp = arr[diff]; arr[diff] = arr[i]; arr[i] = temp; 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 →