Minimum Swaps 2

  • + 0 comments
    def minimumSwaps(arr):
        num_swap = 0
        ordred = sorted(arr)
        for i in range(len(arr)):
            if arr == ordred:
                break
            if ordred[i] == arr[i]:
                continue
            else:
                j = arr.index(ordred[i])
                arr[i], arr[j] = arr[j], arr[i]
                num_swap += 1
        return num_swap