Data Structures & AlgorithmsVery hardTCS NQT · Infosys

What is the number of occurrences of the substring ana in bananaanana, counting overlapping occurrences?

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

Correct answer: C. 4

Overlapping matches share the 'a' in the middle, so each start position is checked separately. Non-overlapping search misses some matches.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic