Data Structures & AlgorithmsHardCodeforces Div2 C · GATE CS

In the string "ababababa", how many times does "aba" occur, counting overlapping occurrences?

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

Correct answer: D. 4

Overlapping occurrences start at every index where the pattern matches. Positions 0, 2, 4 and 6 match, so the count is 4.

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

Exams that ask this topic