Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT

What is the length of the longest substring of "aaabbcccbbaad" in which EVERY letter that appears in the substring appears at least 2 times?

  1. A. 13
  2. B. 12
  3. C. 3
  4. D. 7

Correct answer: B. 12

'd' occurs only once, so no valid substring can contain it; splitting there leaves 'aaabbcccbbaa', where every letter appears at least twice: length 12. Keeping 'd' gives 13, while 3 ('aaa') and 7 ('bbcccbb') are shorter valid pieces.

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

Exams that ask this topic