Rotate Array by K
Riverbend FM keeps a fixed playlist and shifts it every night so listeners do not hear the same track in the same slot two days running. The shift moves each track later in the running order by a set number of slots, and the tracks pushed off the end come back around at the start. The station has been running for years, so the shift number the scheduler sends can be far larger than the number of tracks.
Task: Print the playlist after shifting every track k slots later, with anything pushed off the end wrapping back to the front.
Input
Two lines. The first holds between 1 and 1000 integers separated by single spaces — the track numbers in running order. The second holds a single integer k, where 0 ≤ k ≤ 1,000,000,000.
Output
One line holding the shifted playlist, separated by single spaces.
Example:
Input:
1 2 3 4 5
2
Output:
4 5 1 2 3
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in