Back to DSA

Implement Stack using Queues

easy
Acceptance: 57%
StackQueueDesign

Build a LIFO stack using only queue operations (enqueue at back, dequeue from front, peek at front, check if empty). Your MyStack class must provide push, pop, top, and empty, behaving identically to a standard stack.

Examples

Example 1:
Input:MyStack(), push(3), push(7), top(), pop(), empty()
Output:[null,null,null,7,7,false]

Hints

00:00
1234567