dsa · easy
Implement Queue using Stacks
Implement a FIFO queue using **only stacks**: push, pop, peek, empty.
pop / peek are never called on empty except through empty().
Methods
MyQueue()construct the structureempty()trueif no elementspush(value)push onto the structurepeek()the front value, without removing itpop()remove the top/front as the statement defines (not called on empty unless noted)
Fill in the MyQueue class. The starter already walks ops / args and calls your methods — leave the driver at the bottom as-is. Constructors contribute null; booleans print as true / false.
Example
`` MyQueue() → null push(1) → null push(2) → null peek() → 1 pop() → 1 empty() → false ``
Constraints
Calls <= 100
Examples
Example 1
Input: ["MyQueue","push","push","peek","pop","empty"] [[],[1],[2],[],[],[]] Expected: [null,null,null,1,1,false]