Data Structures & AlgorithmsHardProduct placement · Amazon/Microsoft

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

  1. A. 136; 3
  2. B. -100; 2
  3. C. -100; 3
  4. D. 136; 4

Correct answer: A. 136; 3

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

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

Exams that ask this topic