#C6962. Right Rotation of Array

    ID: 50780 Type: Default 1000ms 256MiB

Right Rotation of Array

Right Rotation of 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. That is, each element is moved k positions to the right, and the elements that go beyond the last position re-enter at the beginning of the array.

You should perform this rotation in-place, using O(1) extra space and in O(n) time. Note that the effective rotation can be calculated using the formula \( k \mod n \) where \( n \) is the length of the array.

inputFormat

The input consists of three parts:

  1. The first line contains a single integer \( n \), the number of elements in the array.
  2. The second line contains \( n \) space-separated integers representing the array.
  3. The third line contains an integer \( k \), the number of steps to rotate the array.

outputFormat

Output the rotated array as a single line of \( n \) space-separated integers.

## sample
7
1 2 3 4 5 6 7
3
5 6 7 1 2 3 4