Implement Stack Using Array

Implement a stack using an array with the following operations:

  • push(x): push x onto the stack.
  • pop(): remove the element on top of the stack.
  • top(): read the top element.
  • empty(): report whether the stack is empty.

You are given two parallel arrays, operations and values, of equal length. Execute the operations in order against a single stack. The two arrays are aligned by index: values[i] is the argument for operations[i]. When operations[i] is "push", values[i] is the value pushed. For every other operation, values[i] is ignored; a placeholder 0 is used by convention.

Return one integer array holding the result of every top() and empty() call, in order. top() contributes the current top value, or -1 when the stack is empty. empty() contributes 1 when the stack is empty and 0 otherwise. push and pop contribute nothing.

Examples
Input: [["push","top","pop"],[1,0,0]]
Output: [1]
Hints

Implement Stack Using Array

Implement a stack using an array with the following operations: