Arrays: Left Rotation

  • + 0 comments
    def rotLeft(a, d):
        # Write your code here
        n = len(a)
        nums = []
        js = []
        for i, num in enumerate(a):
            j = i-d
            if j < 0:
                j = n+j
            else:
                j = j
            js.append(j)
            nums.append(num)
        new_a = sorted(zip(js, nums))
        arr = []
        for item in new_a:
            arr.append(item[1])
        return arr