🎙 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 12 of 13

In a queue built from two stacks, when are items moved from the in-stack to the out-stack?

In a queue built from two stacks, when are items moved from the in-stack to the out-stack?

  1. A.After every push
  2. B.After every pop
  3. C.Never
  4. D.Only when the out-stack is empty and a pop is requested
Answer & explanation

Correct answer: Only when the out-stack is empty and a pop is requested

Moving only then means each item is moved at most once, which makes each operation amortised O(1).

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 →