Round the Queue
People stand in a queue, and names[0] is at the front. One move sends the person at the front to the back of the queue, and everybody else steps forward.
Return the name of the person at the front after moves moves. moves can be huge, so think before you act it out step by step.
Example 1
names ["ann","bo","cy"]
moves 1
returns "bo"
ann goes to the back, and bo is at the front.
Example 2
names ["ann","bo","cy"]
moves 3
returns "ann"
After three moves each of the three has gone to the back once, and the queue is as it was.
Example 3
names ["ann","bo","cy"]
moves 1000000000
returns "bo"
A billion moves are 333,333,333 full rounds of three and then one more move, which leaves bo in front.
Constraints
1 <= len(names) <= 12, and all the names are different0 <= moves <= 10**9
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Stacks and queues problems
- Served in OrderBeginner
- Stack After CommandsBeginner
- Typing With UndoBeginner
- Card WarEasy
- Cups on the CounterEasy
- Depth If BalancedEasy
- Drop the Unmatched BracketsEasy
- Editor With Undo and RedoEasy