#K81657. Rotate Array
Rotate Array
Rotate Array
You are given an array of n integers and a non-negative integer d. Your task is to rotate the array to the right by d positions. In other words, move each element of the array d positions to the right, with the elements at the end wrapping around to the start.
If d is greater than or equal to n, use the effective rotation of \(d \bmod n\) instead.
Example: For n = 5, d = 2 and array = [1, 2, 3, 4, 5], the output should be [4, 5, 1, 2, 3].
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains two integers \(n\) and \(d\), where \(n\) is the number of elements in the array and \(d\) is the number of positions to rotate the array.
- The second line contains \(n\) space-separated integers representing the elements of the array.
If \(n = 0\), the second line will be empty.
outputFormat
Output a single line via standard output containing the rotated array. The elements should be printed in order, separated by a single space.
## sample5 2
1 2 3 4 5
4 5 1 2 3