Rotate the array to the right by k positions.
Input
- Line 1: n (
1 ≤ n ≤ 10^5)
- Line 2: n integers
- Line 3: k (
0 ≤ k ≤ 10^9)
Output
The rotated array, space separated.
Hint
k can be larger than the array, so start with k % n. The elegant in-place trick is three reversals: whole array, first k, then the rest.
Read from standard input and write to standard output. 5 test cases in total (3 hidden). Tests for this language run inside your browser.