193. Implement Queue using Stacks

Easy · Stack

Implement a first-in, first-out (FIFO) queue using only stack operations (push to top, pop from top, peek at top, and check if empty). Your queue must support the following operations: `push(x)` — pushes element x to the back of the queue, `pop()` — removes and returns the element from the front of the queue, `peek()` — returns the element at the front of the queue without removing it, and `empty()` — returns true if the queue is empty, false otherwise.

You are given a list of operations and their arguments to simulate. The input is an array of two arrays: the first is a list of operation names (strings), and the second is a list of arguments for each operation (each argument is itself an array; push has one element, others are empty arrays). Return an array of results for each operation — use `null` for operations that don't return a meaningful value (i.e., `push`).

Note: You may only use standard stack operations internally (push to top, pop from top, peek top, size, and is empty).

Examples

Example 1
Input: ops = ["push","push","peek","pop","empty"], args = [[1],[2],[],[],[]]
Output: [null, null, 1, 1, false]
Explanation: push(1) → queue: [1]; push(2) → queue: [1,2]; peek() → 1 (front); pop() → 1, queue: [2]; empty() → false
Example 2
Input: ops = ["push","pop","empty"], args = [[5],[],[]]
Output: [null, 5, true]
Explanation: push(5) → queue: [5]; pop() → 5, queue: []; empty() → true

Constraints