Data Structures & AlgorithmsModerateWipro · Accenture pattern

What is the value of the prefix expression + * 3 4 − 9 / 8 2 ?

  1. A. 17
  2. B. 12
  3. C. 8
  4. D. 21

Correct answer: A. 17

Scan right to left with a stack (the first popped value is the LEFT operand): 8 / 2 = 4; 9 − 4 = 5; 3 * 4 = 12; 12 + 5 = 17. Taking the first popped value as the RIGHT operand instead turns 9 − 4 into 4 − 9 and 8 / 2 into 2 / 8, which derails the result.

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

Exams that ask this topic