Data Structures & AlgorithmsModerateGATE CS · TCS NQT

How many occurrences of the pattern aba are found in the string abababa when occurrences may overlap?

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

Correct answer: C. 3

Overlapping occurrences start at every index where the pattern matches, here positions 0, 2 and 4. Non-overlapping search would report only 2.

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

Exams that ask this topic