Left Rotation

  • + 0 comments

    Python Solution with minimum no of rotations remainder = minimum no. of rotations or swaps required on the arr

    def rotateLeft(d, arr):
        n=len(arr)
        rem=d%n
        if d==0 or rem==0:
            return arr
        else:
            for i in range(rem):
                arr.append(float('-inf'))
                arr[0],arr[-1]=arr[-1],arr[0]
                arr.pop(0)
            return arr