#K77647. Rotate Array

    ID: 34911 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

Given an array of integers and an integer \( k \), your task is to rotate the array to the right by \( k \) steps.

The rotation should be done in-place with \( O(1) \) extra space. After rotation, the elements moved past the end of the array wrap around to the beginning.

For example, if the input array is [1,2,3,4,5,6,7] and \( k = 3 \), the rotated array will be [5,6,7,1,2,3,4].

inputFormat

The input is read from standard input (stdin) and consists of three lines:

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

outputFormat

Output the rotated array as a single line of space-separated integers to standard output (stdout).

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