You are viewing a single comment's thread. Return to all comments →
C#
static int minimumSwaps(int[] arr) { var swapsCount = 0; for(int i = 0; i < arr.Length; i++){ if(arr[i] != i+1){ swap(arr, i, arr[i] -1); i--; swapsCount++; } } return swapsCount; } static void swap(int[] arr, int indexA, int indexB){ var temp = arr[indexA]; arr[indexA] = arr[indexB]; arr[indexB] = temp; }
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#