Data Structures & AlgorithmsVery hardTCS NQT · Infosys

Repeatedly delete any two adjacent equal characters from the string abbacbaca until no such pair exists. How many characters remain?

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

Correct answer: A. 5

A stack handles this in one pass: push each character unless it equals the top, in which case pop. The final stack size is the answer, and the order of deletions does not matter.

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

Exams that ask this topic