A rotating status beacon holds an array of n integer readings. A right-rotation by one position moves every reading one slot to the right, and the last reading wraps around to the front. Perform a right-rotation by exactly k positions and report the resulting array.
Formally, after the rotation the reading originally at index i (0-indexed) ends up at index (i + k) mod n.
Line 1: two integers n and k.
Line 2: n space-separated integers, the readings in order.
n space-separated integers on one line: the array after rotating right by k.
Example 1
Input
5 2 1 2 3 4 5
Expected
4 5 1 2 3
Explanation
Rotating right by 2 moves the last two readings (4 5) to the front, giving 4 5 1 2 3.
Example 2
Input
3 5 1 2 3
Expected
2 3 1
Explanation
5 rotations on 3 readings equals 5 mod 3 = 2 rotations, so the last two (2 3) move to the front: 2 3 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →