Data Structures & AlgorithmsHard

When repeatedly deleting adjacent pairs of different letters, why does the final length have fixed parity?

  1. A. Each deletion removes exactly two characters, so the length changes by two and its parity never changes.
  2. B. Each deletion removes exactly one character, so parity alternates.
  3. C. The final length always equals the original length.
  4. D. Parity is determined by the first letter only.

Correct answer: A. Each deletion removes exactly two characters, so the length changes by two and its parity never changes.

Removing two characters at a time preserves the length modulo two, so the final length has the same parity as the start. This gives a quick sanity check on any reduction answer.

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

Exams that ask this topic