Data Structures & AlgorithmsHardICPC regional · Product Company SDE

Problem: What is the length of the longest substring of "aabbcbbcc" in which every character occurs at least twice?

  1. A. 4
  2. B. 2
  3. C. 9
  4. D. 7

Correct answer: C. 9

The whole string has a ×2, b ×4, c ×3, so all 9 characters qualify. Requiring exactly two of each gives 4 ("aabb"), a single run gives 2, and skipping the leading "aa" gives 7.

More Coding Interview Problems questions

Exams that ask this topic