Data Structures & AlgorithmsModerateCodeforces Div2 B · TCS NQT

What is the minimum number of characters you must DELETE from "aabbbcaaddd" so that no two adjacent characters are equal?

  1. A. 6
  2. B. 7
  3. C. 11
  4. D. 3

Correct answer: A. 6

Runs are aa, bbb, c, aa, ddd; a run of k letters needs k − 1 deletions: 1 + 2 + 0 + 1 + 2 = 6. Subtracting the 4 distinct letters from 11 gives 7, 11 deletes everything and 3 counts the letters that occur more than once.

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

Exams that ask this topic