Data Structures & AlgorithmsVery hardGATE CS · TCS NQT

Repeatedly remove adjacent equal characters from "abbaca" using a stack. How many characters are removed in total?

  1. A. 5
  2. B. 4
  3. C. 2
  4. D. 6

Correct answer: B. 4

A stack that pops on a match performs the reductions in one pass; the final string is "ca", so 4 characters are removed.

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

Exams that ask this topic