Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: How many substrings of "eceba" contain exactly 2 distinct characters?

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

Correct answer: A. 5

Test every substring for exactly two distinct letters. The at-most-two count minus the at-most-one count gives the same result, so the two methods can be used to cross-check.

More Coding Interview Problems questions

Exams that ask this topic