#C11419. Rotate Array
Rotate Array
Rotate Array
Given an array of integers and a non-negative integer k, the task is to rotate the array to the right by k steps.
The rotation is performed in such a way that the last k elements of the array will appear at the beginning and the rest of the elements will follow. Formally, for an array \(A\) of length \(n\) and an integer \(k\), the rotated array is defined as:
\(A' = \{ A_{(n-k) \bmod n}, A_{((n-k+1)\bmod n)}, \dots, A_{((n-1)\bmod n)}, A_{0}, A_{1}, \dots, A_{((n-k-1)\bmod n)} \}\)
For example, if the array is [1, 2, 3, 4, 5] and \(k=2\), the rotated array becomes [4, 5, 1, 2, 3].
inputFormat
The input is given via stdin and consists of two lines.
- The first line contains two space-separated integers: \(n\) (the number of elements in the array) and \(k\) (the number of steps to rotate the array).
- The second line contains \(n\) space-separated integers representing the array. If \(n = 0\), the second line will be empty.
outputFormat
Output the rotated array as a sequence of space-separated integers on a single line via stdout. If the array is empty, output an empty line.
## sample5 2
1 2 3 4 5
4 5 1 2 3