Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

rotate array python

def rotate(arr,n,k):
    # write your code here
    k = k % n
    k = n - 1 - k
    arr[:] =  arr[k+1:] + arr[0:k+1]
    #print(arr[0:k+1])
    return arr
    
def main():
    n=int(input())
    arr=[]
    for i in range(n):
        val=int(input())
        arr.append(val)
    k=int(input())
    arr = rotate(arr,n,k)
    for i in range(n):
        print(arr[i],end=" ")

main()
 
PREVIOUS NEXT
Tagged: #rotate #array #python
ADD COMMENT
Topic
Name
4+3 =