Data Structures & AlgorithmsHardCodeforces Div2 C · TCS NQT

Repeatedly delete any two adjacent equal letters in "abbacddcaeeaf" until no such pair remains. What is the length of the final string?

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

Correct answer: B. 1

A stack handles this: push each letter, and pop when it equals the top. Each deletion removes two letters, and deleting pairs in a different order can still end in the same reduced string, which the stack finds in one pass.

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

Exams that ask this topic