Data Structures & AlgorithmsHardTCS NQT · Infosys

Start with the stack [1]. Operations in order: DUP (push a copy of the top), ADD (pop two and push their sum), DUP, DUP, ADD, ADD. What is the final top value?

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

Correct answer: C. 6

The stack evolves as [1,1], [2], [2,2], [2,2,2], [2,4], [6]; the final top is 6.

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

Exams that ask this topic