You are viewing a single comment's thread. Return to all comments →
function minimumSwaps(arr) { let count = 0 for(let i=0; i < arr.length; i++) { const current = arr[i] const actualValue = i+1 if(current != actualValue){ const swapIndex = arr.findIndex((n) => n === actualValue) arr[i] = actualValue arr[swapIndex] = current count++ } } 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 →