You are viewing a single comment's thread. Return to all comments →
C solution
int minimumSwaps(int arr_count, int* arr) { int swaps = 0; for (int i = 1; i <= arr_count; i++) { if (arr[i-1] != i) { for (int j = i; j < arr_count; j++) { if (i == arr[j]) { int temp = arr[i-1]; arr[i-1] = arr[j]; arr[j] = temp; swaps++; break; } } } } return swaps; }
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
C solution