FunctionRacerProblemsRace

Round the Queue

BeginnerStacks and queuesPython, JavaScript, TypeScript, Java, C++

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

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Stacks and queues problems