Data Structures & AlgorithmsVery hardCodeforces Div2 C · TCS NQT

What is the minimum number of characters you must delete from "abbabaab" (keeping the order of the rest) so that the result contains NO substring "ab"?

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

Correct answer: C. 3

Every 'ab' in the text must lose one of its letters, but deleting a letter can join its neighbours into a new 'ab'. So the minimum comes from a left-to-right DP whose state is the last kept letter, not from counting the existing occurrences.

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

Exams that ask this topic