Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A stack-based reduction processes the string "abbaca" from left to right: if the current character equals the top of the stack, both are removed; otherwise it is pushed. What string remains after processing all characters?

  1. A. ca
  2. B. aaca
  3. C. abca
  4. D. bca

Correct answer: A. ca

A stack removes adjacent equal pairs as they form, so removal can cascade. Checking only the original neighbours (without the stack) misses the cascade.

More Coding Interview Problems questions

Exams that ask this topic