#K66177. Rotate Array Right

    ID: 32363 Type: Default 1000ms 256MiB

Rotate Array Right

Rotate Array Right

Given an array of integers and an integer ( k ), rotate the array to the right by ( k ) positions. The rotation is defined as moving the last ( k ) elements to the front of the array in order. In particular, if ( n ) is the length of the array, then each element at index ( i ) moves to index ( (i + k) \mod n ). Your task is to implement this rotation and output the rotated array.

Note: The input will first provide an integer indicating the number of elements in the array, followed by the array elements, and then an integer ( k ). The output should be the rotated array with the elements separated by a space.

inputFormat

The input consists of two lines:

  1. The first line contains an integer ( n ) (the number of elements) followed by a line with ( n ) space-separated integers representing the array.
  2. The second line contains an integer ( k ) indicating the number of positions to rotate the array.

outputFormat

Output the rotated array as a single line of ( n ) space-separated integers.## sample

7
1 2 3 4 5 6 7
3
5 6 7 1 2 3 4

</p>