Implement Queue using Two Stacks
00:00
TCSInfosys
Implement FIFO queue using only two stacks. Support push, pop, peek, empty with amortized O(1) complexity.
Examples
Input → Ex1: push(1),push(2),peek()=1,pop()=1,empty()=False
Output →
Input → Ex2: push(1),pop()=1,empty()=True
Output →
Input → Ex3: push(1),push(2),push(3),pop()=1,pop()=2,pop()=3
Output →