Data Structures & AlgorithmsHard

What is the minimum number of characters to delete from "aabbbcaa" so that no two ADJACENT characters are equal?

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

Correct answer: B. 4

Each run of equal adjacent letters of length L needs L−1 deletions, and the total of these is the count of equal adjacent pairs. Counting distinct letters or unequal pairs measures a different quantity.

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

Exams that ask this topic