🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Queues and Deques: all 13 questions

Quiz: Queues and Deques · Question 11 of 13

What does this print? (code)

What does this print?

inbox, outbox = [], []
def push(x):
    inbox.append(x)
def pop():
    if not outbox:
        while inbox:
            outbox.append(inbox.pop())
    return outbox.pop()
push(1); push(2); push(3)
a = pop()
push(4)
print(a, pop(), pop(), pop())
  1. A.1 2 3 4
  2. B.3 2 1 4
  3. C.1 4 2 3
  4. D.1 2 4 3
Answer & explanation

Correct answer: 1 2 3 4

The queue keeps first-in, first-out order. 4 waits in inbox until outbox is empty, so it comes out last.

Can you get the rest right without peeking?

Take the timed Quiz: Queues and Deques quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →