Data Structures & AlgorithmsModerateTCS NQT · Accenture

Problem: How many occurrences of the substring "ana" are in "bananarama" (overlapping occurrences count)?

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

Correct answer: D. 2

Scan every starting index for the three-letter match, allowing overlaps such as the two 'ana' that share the middle 'n'. Non-overlapping search misses one of them.

More Coding Interview Problems questions

Exams that ask this topic