Data Structures & AlgorithmsModerateCodeforces Div2 B-D · ICPC regional

How many times does the pattern "ababa" occur in the text "ababcababa", counting overlapping occurrences?

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

Correct answer: A. 1

Only index 5 matches: at index 0 the text reads ababc and breaks the pattern at its fifth character, so there is one occurrence.

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

Exams that ask this topic