225. Implement Stack Using Queues
Practice Implement Stack Using Queues for free on NudgeCode: Easy, Stack pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.
Build a last-in-first-out stack using only queue operations (add to back, remove from front, look at front, size, is empty).
push(x)putsxon toppop()removes and returns the top elementtop()returns the top elementempty()returns whether the stack is empty
Each test is a list of operations and their arguments; the expected output lists what each call returns (null for calls that return nothing).
Example
["MyStack","push","push","top","pop","empty"]
[[],[1],[2],[],[],[]]
-> [null,null,null,2,2,false]
Constraints
popandtopare only called on a non-empty stack- at most 100 calls