Right Rotation

Report a typo

Right rotation is an operation that shifts each element of the array to the right.

If the right rotation is 1 with the array of {1,2,3,4,5}, the new array is going to be {5,1,2,3,4}.
Another example, if the rotation is 2, the array is {1,2,3,4,5}, the new array will be {4,5,1,2,3}, because
{1,2,3,4,5} -> {5,1,2,3,4} -> {4,5,1,2,3}.

The first line of the input contains the number of elements in the array, N.
The next N lines contain the elements of the array.
The last is the value of the rotation.

The output contains the shifted elements of the array. Separate the elements by the space character.

If you need to shift an array that consists of 5 elements to 11, you can shift it by 1 instead. Try to reduce the number of shifts!

Sample Input 1:

5
1
2
3
4
5
1

Sample Output 1:

5 1 2 3 4

Sample Input 2:

5
1
2
3
4
5
5

Sample Output 2:

1 2 3 4 5
Write a program in Kotlin
fun main() {
// write your code here
}
___

Create a free account to access the full topic