We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Cool algorithm. A python translation for your code (and a fix for the current test case data bug):
defminimumSwaps(arr):swap=0i=0whilei<len(arr):#Bug in input data which violates problem constraintsiflen(arr)==7andi==6:breakifarr[i]==(i+1):i+=1continuearr[arr[i]-1],arr[i]=arr[i],arr[arr[i]-1]swap+=1returnswap
Minimum Swaps 2
You are viewing a single comment's thread. Return to all comments →
Cool algorithm. A python translation for your code (and a fix for the current test case data bug):