Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: A string is "xoxoxox". How many substrings of length 3 are equal to "xox"?

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

Correct answer: D. 3

Overlapping occurrences count: 'xox' appears at indices 0, 2 and 4, so the answer is three. Non-overlapping scanning would find only two.

More Coding Interview Problems questions

Exams that ask this topic