Write a program to cyclically rotate an array by one. |450DSA|Cyclically rotate an array by one

admin
By -
0

 

Given an array, rotate the array by one position in clock-wise direction.



Example 1:

Input:
N = 5
A[] = {1, 2, 3, 4, 5}
Output:
5 1 2 3 4

 solution
    last=arr[n-1]
    for i in range(n-2,-1,-1):
        arr[i+1]=arr[i]
    arr[0]=last

Post a Comment

0Comments

Put Your Thought or Query Here

Post a Comment (0)