Question queue

Write code · Medium · §5.2 Queues

waiting holds the viewer numbers of the people who lined up to ask questions on a live stream, in the order they lined up. The front of the line is waiting[0]. The host performs the actions in actions in order. "answer" answers the question of the viewer at the front, and that viewer leaves the line. "later" sends the viewer at the front to the back of the line.

If a viewer who has already been sent back by "later" once gets "later" again, that viewer leaves the line without asking instead of going to the back. If the line is empty, an action does nothing. Complete the function solution, which returns a list of the numbers of the viewers whose questions were answered, in the order they were answered. If no question was answered, return an empty list [].

Function

solution(waiting, actions)

Constraints

Examples

waitingactionsresult
[7, 3, 9]['answer', 'later', 'answer', 'answer'][7, 9, 3]
[10, 20, 30, 40]['later', 'answer', 'later', 'answer', 'answer'][20, 40, 10]

Starter code

def solution(waiting, actions):
    answer = []
    return answer

Solve this problem in your browser

Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.