#C498. Rotate Array to the Right
Rotate Array to the Right
Rotate Array to the Right
You are given an array of integers and an integer \( k \). Your task is to rotate the array to the right by \( k \) steps. That is, every element should be shifted to the right by \( k \) positions, and the elements at the end of the array wrap around to the beginning.
Example:
Input: 7 1 2 3 4 5 6 7 3 Output: 5 6 7 1 2 3 4
Note that the rotation is performed in-place. You must use the modulo operator to handle the case where \( k \) is greater than the length of the array.
inputFormat
The input consists of three lines:
- The first line contains an integer \( n \) representing the number of elements in the array.
- The second line contains \( n \) space-separated integers representing the array.
- The third line contains an integer \( k \) representing the number of rotation steps to the right.
outputFormat
Output the rotated array as \( n \) space-separated integers on a single line.
## sample7
1 2 3 4 5 6 7
3
5 6 7 1 2 3 4