#C1421. Rotate Array

    ID: 43834 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

You are given an array of integers and a non-negative integer k. Your task is to rotate the given array to the right by k steps. The rotation should be done in-place with O(1) extra memory. This problem tests your ability to manipulate arrays and implement efficient in-place algorithms.

For example, if the array is [1, 2, 3, 4, 5, 6, 7] and k is 3, then after rotation the array becomes [5, 6, 7, 1, 2, 3, 4].

The mathematical formulation for the effective rotation is given by:

\( k_{eff} = k \mod n \)

where \(n\) is the length of the array.

inputFormat

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

  • The first line contains space-separated integers representing the array elements.
  • The second line contains a single integer k which indicates the number of steps to rotate the array.

outputFormat

Print the rotated array to standard output (stdout) in a single line with each element separated by a space.

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