Data Structures & AlgorithmsModerateTCS NQT · Codeforces Div2 B

What is the minimum number of characters you must delete from "aaabbbbcccccdd" so that no three equal letters are consecutive?

  1. A. 8
  2. B. 6
  3. C. 10
  4. D. 5

Correct answer: B. 6

Each maximal run of length L must shrink to at most 2, costing max(0, L − 2) deletions, and runs are independent. Deleting every letter that repeats the previous letter removes too many.

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

Exams that ask this topic