Implement Stack using Two Queues

00:00
EasyQueueStackDesign
TCSWipro

Implement a LIFO stack using only two queues. Support push, pop, top, and empty operations.

Examples

Input → Ex1: push(1),push(2),top()=2,pop()=2,empty()=False
Output →
Input → Ex2: push(1),pop()=1,empty()=True
Output →
Input → Ex3: push(1),push(2),push(3),pop()=3,pop()=2,pop()=1
Output →