Gamified challenge · Queues
Print jobs wait in a line. priorities[i] is the priority of job i (bigger is more urgent), and job 0 is at the front. The printer repeats: take the job at the front; if any job still waiting has a higher priority, put the taken job at the back of the line; otherwise print it.
Write printTurn(priorities, mine) (Python: print_turn(priorities, mine)) that returns on which turn job mine is printed: 1 if it is the first page out, 2 if second, and so on. Jobs with equal priority don't block each other.
For [2, 1, 3, 2] with mine = 2: job 0 and job 1 go to the back, then job 2 (priority 3) prints first, so the answer is 1. For [1, 1, 9, 1, 1, 1] with mine = 0, the answer is 5.
This game is part of the paid plans. Sign in, then pick a plan to write your answer, watch it play out, and step through the algorithm with its guide.
Sign in with Google