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

A queue built from two stacks: what is the cost of each operation?

A queue built from two stacks: what is the cost of each operation?

  1. A.O(n) every time
  2. B.amortised O(1)
  3. C.O(log n)
  4. D.O(1) for push, O(n²) for pop
Answer & explanation

Correct answer: amortised O(1)

Each element is moved from inbox to outbox at most once over its lifetime.

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 →