#K35397. Rotate Array

    ID: 25522 Type: Default 1000ms 256MiB

Rotate Array

Rotate Array

Given an array of integers and a non-negative integer k, rotate the array to the right by k steps.

In other words, move each element of the array to the right by k positions. Elements that fall off the end of the array reappear at the beginning. Formally, for an array \(A\) of length \(n\), the element at index \(i\) moves to index \((i+k) \mod n\).

Your task is to implement an efficient solution to perform this rotation.

inputFormat

The input consists of two lines. The first line contains two space-separated integers: (n) (the number of elements in the array) and (k) (the number of steps to rotate the array). The second line contains (n) space-separated integers representing the array.

outputFormat

Output a single line containing the rotated array, with elements separated by a single space.## sample

5 2
1 2 3 4 5
4 5 1 2 3