Data Structures & AlgorithmsHard
How many contiguous substrings of "abaabbaab" contain EXACTLY one 'b' and at least two 'a's?
- A. 15
- B. 6
- C. 26
- 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.
Practise more Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questionsArrays, Strings, Linked Lists, Stacks, Queues and Hashing: notes and key points
More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions
- What is the maximum sum of a contiguous subarray of 3 5 2 7 9 1 4 11 in which every element is ODD?
- How many contiguous subarrays of 1 3 4 7 9 6 11 of length at least 2 contain EXACTLY one even value?
- How many contiguous subarrays of 2 5 1 2 4 7 have length at least 2, contain pairwise DISTINCT values, and have an ODD sum?
- How many index pairs i < j in 1 2 3 4 6 8 satisfy A[i]·A[j] ≥ 2·(A[i] + A[j])?
- Why is a sum of XORs over subarrays NOT equal to the sum of the subarray sums?
- When counting subarrays with sum divisible by m, why does the prefix-remainder method count pairs of equal remainders?