dsa · easy

Implement Stack using Queues

GreyOrangeStackQueueDesignFoundation

Implement a LIFO stack using **only FIFO queues**: push, pop, top, empty.

You may use one or two queues. Empty is never popped/topped except via empty().

Fill in the MyStack 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**

`` MyStack() → null push(1) → null push(2) → null top() → 2 pop() → 2 empty() → false ``

Constraints

Calls <= 100

Examples

Example 1

Input:
["MyStack","push","push","top","pop","empty"]
[[],[1],[2],[],[],[]]

Expected:
[null,null,null,2,2,false]

Open in the Dojo editor