Data Structures & AlgorithmsVery hardICPC regional · Amazon SDE OA

Evaluate the postfix expression "3 4 min 5 max 2 +" where min and max take two operands and return the smaller or larger.

  1. A. 8
  2. B. 6
  3. C. 7
  4. D. 14

Correct answer: C. 7

Process tokens left to right with a stack: 3 and 4 give min 3, which is pushed; 5 then gives max(3, 5) = 5; the final 2 is added to 5 to give 7.

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

Exams that ask this topic