#C14038. Rotate List
Rotate List
Rotate List
You are given a list of integers and an integer k
. Your task is to rotate the list to the right by k
steps. This means that the last k
elements of the list should be moved to the beginning while the remaining elements shift to the right.
If k
is greater than the number of elements in the list, then the list should be rotated k \mod n
times, where n
is the size of the list.
For example, given the list [1, 2, 3, 4, 5, 6, 7]
and k = 3
, the rotated list will be [5, 6, 7, 1, 2, 3, 4]
.
inputFormat
The input consists of two lines:
- The first line contains two integers n and k, where n is the number of elements in the list and k is the number of steps to rotate.
- The second line contains n space-separated integers representing the list elements. If n is zero, the list is empty.
outputFormat
Output the rotated list as a single line of space-separated integers. If the list is empty, output nothing.
## sample7 3
1 2 3 4 5 6 7
5 6 7 1 2 3 4