dsa · easy

Implement Queue using Stacks

GreyOrangeStackQueueDesignFoundation

Implement a FIFO queue using **only stacks**: push, pop, peek, empty.

pop / peek are never called on empty except through empty().

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]

Open in the Dojo editor