Loading...
Loading...
The college quiz app shows a leaderboard of n player IDs on the notice-board screen. Every minute, each ID moves one place to the right, and the last ID wraps around to the first place.
Given the board now and the number of minutes k, print the board after k minutes. The screen may run for a very long time, so k can be much larger than n.
Example 1
Input
5 2 11 22 33 44 55
Output
44 55 11 22 33
After 1 minute: 55 11 22 33 44. After 2 minutes: 44 55 11 22 33.
Example 2
Input
3 7 4 5 6
Output
6 4 5
Every 3 minutes the board is back to the start, so 7 minutes act like 1 minute.
Try the problem first. Open one hint at a time.
Shifting n IDs by n places gives back the same board, so only k % n places matter.
k can be up to 10^18, so read it as a long before you take the remainder.
The ID at index i ends up at index (i + r) % n, where r = k % n.
To avoid a second array: reverse the whole array, then reverse the first r IDs, then reverse the rest.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor