Data Structures & AlgorithmsHardGATE CS · ICPC regional
How many substrings of abcabc contain all of the three letters a, b and c at least once?
- A. 11
- B. 8
- C. 10
- D. 13
Correct answer: C. 10
Count, for each left end, the shortest right end that completes all three letters; every later right end also works. Summing these per-left counts avoids enumerating all substrings.
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
- How many substrings of aabacbebebe contain exactly two distinct characters?
- How many substrings of abcdabcabd are anagrams of the pattern abd (same letters with the same multiplicities)?
- How many contiguous subarrays of [1, 2, 2, 3, 1, 1] contain no two adjacent equal elements?
- What is the length of the shortest contiguous subarray of [2, -1, 2, 4, -3, 5] whose sum is at least 7?
- What is the minimum number of characters that must be deleted from aaaabbbbcccdd so that no two letters occur the same number of times?
- How many distinct values appear among the sums of all non-empty contiguous subarrays of [1, 2, 3]?