You are viewing a single comment's thread. Return to all comments →
Hey, this python code works!
def minimumSwaps(arr): swaps = 0 for i in range(len(arr)): running_index = i is_loop = False while arr[running_index] != running_index+1: is_loop=True next_index = arr[running_index]-1 arr[running_index] = running_index+1 running_index = next_index swaps +=1 if is_loop: swaps -= 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 →
Hey, this python code works!