A conveyor belt carries n items, numbered by position 1..n, each holding a given item ID. The belt is rotated left by k steps: this is equivalent to removing the first k items from the front (in order) and appending them, still in order, to the back. k may be larger than n (in which case only k mod n steps actually change anything). Print the resulting sequence of item IDs after the rotation.
Line 1: two integers n k.
Line 2: n space-separated integers, the item IDs.
n space-separated integers: the item IDs after rotating left by k (equivalently k mod n) positions.
Example 1
Input
5 2 10 20 30 40 50
Expected
30 40 50 10 20
Explanation
Removing the first 2 items (10, 20) and appending them to the back gives 30 40 50 10 20.
Example 2
Input
4 0 1 2 3 4
Expected
1 2 3 4
Explanation
k=0 means no rotation happens, so the array is unchanged.
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 →