Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: Find the length of the longest substring of "aaabbbbcccd" that contains at most two distinct letters.

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

Correct answer: B. 7

"aaabbbb" has two letters and length 7; the b- and c-runs give only 4 + 3. A single run gives 4, three letters gives "aaabbbbccc" (10), and 11 is the whole string.

More Coding Interview Problems questions

Exams that ask this topic