Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Evaluate the postfix expression "3 4 + 2 * 7 −" using a stack (the operator pops the top two values, computes second-from-top op top). What is the result?

  1. A. 7
  2. B. -7
  3. C. 4
  4. D. 14

Correct answer: A. 7

3 4 + leaves 7, 2 * leaves 14, and 7 − computes second-from-top minus top = 14 − 7 = 7. Popping in the wrong order gives 7 − 14 = −7, reading the tokens as infix 3 + 4 × 2 − 7 gives 4, and stopping before the last operator leaves 14.

More Coding Interview Problems questions

Exams that ask this topic