You are viewing a single comment's thread. Return to all comments →
def minimumSwaps(arr): temp = [0] * (len(arr) + 1) for pos, val in enumerate(arr): temp[val] = pos pos += 1 swaps = 0 for i in range(len(arr)): if arr[i] != i+1: swaps += 1 t = arr[i] arr[i] = i+1 arr[temp[i+1]] = t temp[t] = temp[i+1] return swaps
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 →