Data Structures & AlgorithmsHardTCS NQT · Infosys

A backspace text editor reads the string a##b#cd# where each # deletes the previous character if one exists. How many characters remain in the final text?

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

Correct answer: A. 1

Simulate with a stack: each letter pushes, each # pops only when the stack is non-empty. A # on an empty stack must not remove anything.

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

Exams that ask this topic