Data Structures & AlgorithmsVery hardGATE CS · ICPC regional

What is the minimum number of characters that must be deleted from aabbaa so that no two adjacent characters of the remaining string are equal (characters may be deleted from any positions)?

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

Correct answer: D. 3

The longest subsequence with no equal neighbours is aba, of length 3, so 6 - 3 = 3 deletions are needed.

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

Exams that ask this topic