Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft

Evaluate the postfix expression 7 4 − 2 + 6 − 8 × 7 1 + + (all divisions are exact). What is its value, and what is the maximum number of operands on the stack at any moment?

  1. A. 0; 4
  2. B. 64; 3
  3. C. 0; 3
  4. D. 64; 2

Correct answer: C. 0; 3

On each operator pop b (top) then a, and push a op b — the first popped value is the RIGHT operand. Tracing gives 0, with the stack peaking at 3 values. Swapping the operand order gives 64.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic