#K39827. Right Rotation of a List
Right Rotation of a List
Right Rotation of a List
You are given an integer ( n ) representing the size of a list, a list of ( n ) integers, and an integer ( k ). Your task is to rotate the list to the right by ( k ) positions. The rotation is performed in such a way that each element moves to a new position according to the formula: if the original index is ( i ), the new index becomes ( (i + k) \mod n ). For example, given ( n = 5 ), list = [1, 2, 3, 4, 5] and ( k = 2 ), the rotated list is [4, 5, 1, 2, 3].
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer ( n ), the number of elements in the list.
- The second line contains ( n ) space-separated integers, representing the list elements.
- The third line contains an integer ( k ), the number of positions to rotate the list to the right.
outputFormat
Output the rotated list as a sequence of space-separated integers to standard output (stdout).## sample
5
1 2 3 4 5
2
4 5 1 2 3