Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: How many indices i satisfy s[i] = s[i+2] in the string "abcabcab" (0 ≤ i ≤ n−3)?

  1. A. 1
  2. B. 2
  3. C. 3
  4. D. 0

Correct answer: D. 0

Compare each character with the one two positions ahead. Comparing neighbours (distance one) answers a different question.

More Coding Interview Problems questions

Exams that ask this topic