Data Structures & AlgorithmsModerateTCS NQT · Infosys

Problem: The string "aabbccdd" has all its letters doubled. How many substrings of length 2 consist of two identical letters?

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

Correct answer: B. 4

Adjacent equal pairs occur at positions 0, 2, 4 and 6 (the doubled letters), so the answer is four.

More Coding Interview Problems questions

Exams that ask this topic