#K16331. Right Rotation of Array

    ID: 24555 Type: Default 1000ms 256MiB

Right Rotation of Array

Right Rotation of Array

You are given an array of integers and a non-negative integer \(k\). Your task is to rotate the array to the right by \(k\) positions.

For example, if \(arr = [1, 2, 3, 4, 5]\) and \(k = 1\), then the rotated array is \( [5, 1, 2, 3, 4] \). Similarly, if \(k = 3\), the rotated array becomes \( [3, 4, 5, 1, 2] \). The rotation is circular, meaning that elements shifted off the end reappear at the beginning of the array.

Please note that if \(k\) is greater than the length of the array, you should use \(k \mod n\), where \(n\) is the number of elements in the array.

inputFormat

The input is read from standard input (stdin) with the following format:

  • The first line contains an integer \(n\), representing the number of elements in the array.
  • The second line contains \(n\) space-separated integers which represent the elements of the array.
  • The third line contains an integer \(k\), representing the number of positions by which the array is to be rotated to the right.

outputFormat

Output the rotated array on a single line. The elements must be printed in order and separated by a single space.

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