Implement a Queue Using Stacks
Problem statement
Implement first-in-first-out queue behavior using stacks: push, pop, top and size are the permitted storage operations; do not use a queue/deque operation that removes from the opposite end. Two stacks are allowed. Return one result per trace entry:0 for enqueue, the removed front for dequeue, the current front for peek, and the item count for size. Empty dequeue/peek return-2147483648, outside the payload domain. Start empty.
Function
queueUsingStacks(operations: int[][]) → int[]Examples
Example 1
operations = [[0,4],[0,7],[2,0],[1,0],[3,0]]return = [0,0,4,4,1]Enqueuing4 before7 leaves4 at the front; removing it leaves one item.
Example 2
operations = [[0,1],[0,2],[1,0],[0,3],[1,0],[1,0],[1,0]]return = [0,0,1,0,2,3,-2147483648]The dequeue order is1,2,3; one additional dequeue is empty.
Constraints
0 <= operations.length <= 500.- Every operation has exactly two entries.
-1000000 <= operations[i][j] <= 1000000.- Every operation is [kind,value], with kind in 0..3. Kind0 adds value; kind1 removes and returns the front item; kind2 returns it without removal; kind3 returns the current size. The second entry is ignored for kinds1..3.