← 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?
- A.O(n) every time
- B.amortised O(1)
- C.O(log n)
- 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 →