#C4607. Rotate Array

    ID: 48164 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

Given an array of integers and an integer k, rotate the array to the right by k steps. The rotation should be performed in such a way that the last k elements of the array are moved to the beginning.

Note: k can be greater than the length of the array. In that case, you should rotate the array by (k mod n) steps, where n is the number of elements in the array.

For example, if the input array is [1, 2, 3, 4, 5, 6, 7] and k = 3, the output should be [5, 6, 7, 1, 2, 3, 4].

The formula for effective rotation is given by \[ k_{eff} = k \mod n \] where \(n\) is the number of elements in the array.

inputFormat

The input is given via standard input and 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 elements. The third line contains an integer k representing the number of steps to rotate the array to the right.

Example:

7
1 2 3 4 5 6 7
3

outputFormat

The output should be printed to standard output. It consists of a single line with n integers representing the rotated array. The integers should be space-separated.

Example:

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