Implement a first-in-first-out (FIFO) queue using only two stacks. The implemented queue should support all the functions of a normal queue.
push(x) — Push element x to the back of queuepop() — Removes the element from the frontpeek() — Get the front elementempty() — Return whether the queue is emptyEach line contains a queue operation.
Input: push 1 push 2 peek pop empty Output: 1 1 false
Print outputs only for peek, pop, and empty.
No submissions yet.
Discuss two-stack approach, amortized complexity, and lazy transfer.