#K85922. Rotate Array
Rotate Array
Rotate Array
You are given an array of integers and an integer k. Your task is to rotate the array to the right by k steps. This means that every element will shift to the right by k positions, and the elements that fall off at the end will wrap around to the beginning.
For example, given the array [1, 2, 3, 4, 5, 6, 7]
and k = 3, the rotated array will be [5, 6, 7, 1, 2, 3, 4]
.
The rotation should be performed in-place if possible. You can assume the array is non-empty.
Note: If k is greater than the length of the array, the effective rotation is k mod n, where n is the number of elements in the array. In latex, this relation is written as \( k \mod n \).
inputFormat
The first line of input contains two integers n and k separated by a space, where n is the number of elements in the array, and k is the number of steps to rotate the array.
The second line contains n space-separated integers representing the elements of the array.
outputFormat
Output the rotated array as a sequence of space-separated integers on a single line.
## sample7 3
1 2 3 4 5 6 7
5 6 7 1 2 3 4