Data Structures & AlgorithmsVery hardTCS NQT · Infosys

How many times does the pattern aba occur in ababababa when occurrences may overlap?

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

Correct answer: B. 4

Overlapping occurrences start at every index where the pattern matches, so the count is the number of valid start positions 0 to 6 that match.

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

Exams that ask this topic