Stack from queues

Write codeMedium20 minMicrosoft and Amazon style

Your task

Implement a LIFO stack using only standard FIFO queue operations (enqueue at back, dequeue from front, peek front, size). Replay operations ["push", x], ["pop"], ["top"], ["empty"] and return the list of results from pop/top/empty (empty returns 1 for true, 0 for false; pop and top return the value). Make push do the rotation work so pop and top are O(1). Assume pop/top are not called on an empty stack.

Examples

stack_via_queue(ops: list[list]) -> list[int]
Example 1
Inputstack_via_queue([["push", 1], ["push", 2], ["top"], ["pop"], ["empty"]])
Output[2, 2, 0]