anotsodev
11/23/2017 - 4:49 PM

CyclicRotation.py

# you can write to stdout for debugging purposes, e.g.
# print("this is a debug message")

def solution(A, K):
    # write your code in Python 3.6
    new_list = A.copy()
    # remain = len(A)-K
    res = 0
    for i in range(K):
        for i in range(len(A)):
            if (i+1) < len(A):
                new_list[i+1] = A[i]
            else:
                new_list[res] = A[i]
                res += 1
        A = new_list.copy()
        res = 0
    return new_list