Data Structures & AlgorithmsHardTCS NQT · Infosys

How many times does the pattern aab occur in the string aabaabaab, counting overlapping matches?

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

Correct answer: B. 3

The pattern occurs at positions 0, 3 and 6; no overlap is possible here since aab cannot start inside itself.

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

Exams that ask this topic