Data Structures & AlgorithmsHardGATE CS · TCS NQT

Apply the operations push 3, push 5, pop, push 7, push 2, pop, pop to an initially empty stack. What is the sum of the values remaining on the stack?

  1. A. 4
  2. B. 3
  3. C. 0
  4. D. 17

Correct answer: B. 3

Simulate the stack: after the pops only 3 remains, so the sum is 3. Summing all pushed values (the last option) ignores the pops.

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

Exams that ask this topic