Array Rotation
Given an array and a rotation count, rotate the array to the right by
that many positions: every element moves right by k spots, wrapping
around from the end back to the start.
Input
$1 is the path to a file with two lines:
<space-separated array elements>
<k>
k is a non-negative integer and may be larger than the number of
elements.
Output
The rotated array, space-separated, on one line.
Constraints
- The array has between 1 and 100,000 elements.
- Elements contain no whitespace.
- If
kis larger than the array length (or a multiple of it), rotate byk mod lengthinstead — e.g. rotating a 3-element array by3(or6, or0) leaves it unchanged.
Example
Input:
apple banana cherry date
2
Output:
cherry date apple banana