Loading...
Loading...
Loading...
At a ticket counter, the token display shows n tokens in a row. Every minute each token moves one place to the right and the last one wraps to the front. Print the row after k minutes.
Example 1
Input
5 1 2 3 4 5 2
Output
4 5 1 2 3
After 1 minute: 5 1 2 3 4. After 2: 4 5 1 2 3.
Example 2
Input
3 7 8 9 4
Output
9 7 8
4 rotations of 3 tokens is the same as 1.
Try the problem first. Open one hint at a time.
Rotating n times gives back the same row, so only k % n rotations matter.
The token at index i ends at index (i + k) % n. Fill a new array that way.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor