Data Structures & AlgorithmsHard

How many contiguous substrings of "abaabbaab" contain EXACTLY one 'b' and at least two 'a's?

  1. A. 15
  2. B. 6
  3. C. 26
  4. D. 5

Correct answer: B. 6

Count substrings by their letter counts: exactly one 'b' and an 'a' count of at least two together define the set. Dropping the 'a' condition, relaxing the 'b' count, or fixing the 'a' count at two each change the total.

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

Exams that ask this topic