Data Structures & AlgorithmsHardGATE CS · TCS NQT

What is the number of occurrences of the pattern abab in the string ababababab, counting overlapping matches?

  1. A. 4
  2. B. 5
  3. C. {C-2}
  4. D. 6

Correct answer: A. 4

Matches start at positions 0, 2, 4 and 6, so the overlapping count is 4. Non-overlapping search would report only 2.

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

Exams that ask this topic