Data Structures & AlgorithmsHardTCS NQT · Accenture

A stack machine runs PUSH 3, PUSH 4, ADD, PUSH 5, MUL in order. The result is the value on top of the stack at the end. What is it?

  1. A. 33
  2. B. 39
  3. C. 35
  4. D. 70

Correct answer: C. 35

ADD leaves 7 on the stack, PUSH 5 puts 5 above it, and MUL multiplies the two top values to give 35. Forgetting that MUL pops two values leaves a larger stack than expected.

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

Exams that ask this topic