A Queue from Two Stacks

easy
Unit 2 · Stacks & Dynamic Programming0/3 to milestone

Implement a FIFO Queue using only two Python lists used as stacks (append/pop from the end). Provide enqueue(x), dequeue() (raises IndexError if empty), peek() and __len__. Each operation must be amortised O(1): only move items from the inbox to the outbox when the outbox is empty.

#stacks#queues#amortised-analysis2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
A Queue from Two Stacks · TechGradify