Implement a Basic Stack
Problem statement
Implement the behavior of a last-in-first-out stack for the operation trace. Return one result per operation:0 for push, the removed value for pop, the current value for top, and the number of items for size. Pop/top on an empty stack return-2147483648, which is outside the payload domain. Start with an empty stack.
Function
runStack(operations: int[][]) → int[]Examples
Example 1
operations = [[0,4],[0,7],[2,0],[1,0],[3,0]]return = [0,0,7,7,1]After pushing4 then7, top and pop both return7; one item remains.
Example 2
operations = [[1,0],[0,-2],[2,0]]return = [-2147483648,0,-2]The initial pop is empty. Pushing-2 makes it the top.
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 top item; kind2 returns it without removal; kind3 returns the current size. The second entry is ignored for kinds1..3.