Minimum Swaps 2

  • + 1 comment
    def minimumSwaps(arr):
        i = 0
        swap = 0
        while i < len(arr):
            if arr[i] == i+1:
                i +=1
            else:
                index = arr[i] -1
                arr[i], arr[index] = arr[index], arr[i]
                swap += 1
        return swap