#C3633. Rotate Array

    ID: 47082 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

Given an array of integers and a non-negative integer k, your task is to rotate the array to the right by k steps. This means that each element at index i moves to index (i+k) \mod n, where \(n\) is the length of the array.

You are required to implement an in-place solution with O(n) time complexity and using constant extra space.

inputFormat

The input is provided via standard input and consists of three lines:

  • The first line contains an integer n, 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, the number of steps to rotate the array.

outputFormat

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

## sample
5
1 2 3 4 5
2
4 5 1 2 3