You are viewing a single comment's thread. Return to all comments →
Python solution with all the base conditions :
def minimumSwaps(arr): arr_sorted = False current_pointer = 0 swaps = 0 while not arr_sorted : if (current_pointer == len(arr)) : arr_sorted = True break if (current_pointer+1 == arr[current_pointer]) : current_pointer += 1 else : ind = arr[current_pointer] - 1 arr[current_pointer], arr[ind] = arr[ind], arr[current_pointer] 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 →
Python solution with all the base conditions :