You are viewing a single comment's thread. Return to all comments →
javascript
function minimumSwaps(arr) { let result = 0, swapped = true while(swapped) { swapped = false for(let i=0;i<arr.length;i++){ if(arr[i] != i+1) { swap(arr, i, arr[i]-1) result++ swapped = true } } } return result } function swap (arr, i1, i2) { let temp = arr[i1] arr[i1] = arr[i2] arr[i2] = 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 →
javascript