Data Structures & AlgorithmsModerateTCS NQT Digital · Infosys

Problem: The regex-like string match: count the substrings of "aabbaab" that match the pattern a+b (one or more a's immediately followed by exactly one b, as contiguous substrings).

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

Correct answer: B. 2

Each match is one or more a's directly followed by a b, so the 'aab' at the start and the 'aab' near the end are the two matches. Counting the b characters alone gives 3, including the lone b that has no a before it.

More Coding Interview Problems questions

Exams that ask this topic