Loading
Loading
A shift roster lists staff in rotation order. Each week the roster rotates: everyone moves k positions later, and whoever falls off the end wraps around to the front.
Rotate the roster right by k positions, in place. Return the rotated roster.
roster = [1, 2, 3, 4, 5, 6, 7], k = 3[1,2,3,4,5,6,7]original[7,6,5,4,3,2,1]reverse everything[5,6,7,4,3,2,1]reverse the first k[5,6,7,1,2,3,4]reverse the rest[5, 6, 7, 1, 2, 3, 4]Sign in to keep a note here. It is free, and nobody else can see it.
Sign inExample 1
Sign in to open hints.
Struggling is where the learning happens. Open this once you have genuinely tried, or once the hints have run out.
O(n) time · O(1) space
Input. Run your code to watch it work on this input, one line at a time.
Running code is turned off on this deployment. You can still read the problem, write code, use hints and the visualizer.
Tab moves focus out of the editor. Press Ctrl+M to let Tab indent instead.
No results yet
Run your code against the sample tests, or submit to run the full suite.
The last three move to the front.
Example 2
Rotating by 5 is the same as rotating by 5 mod 2 = 1.