Data Structures & AlgorithmsHardTCS NQT Digital · Product Company SDE
Problem: How many substrings of "abcabc" contain all three letters a, b and c at least once?
- A. 9
- B. 4
- C. 21
- D. 10
Correct answer: D. 10
For each start, the substring qualifies once it reaches the first index where all three letters have appeared: starts 0..3 contribute 4 + 3 + 2 + 1 = 10. Counting distinct strings gives 9, counting only length-3 windows gives 4, and 21 counts all substrings.
More Coding Interview Problems questions
- Problem: In how many ways can a 1 × 7 strip be tiled completely with tiles of length 1, 2 and 3 (ordered arrangements of tiles count…
- Problem: A rope of integer length 10 is cut into integer pieces (at least two pieces), and the product of the piece lengths is maximised…
- Problem: How many binary strings of length 6 contain neither the substring "00" nor "11"?
- Problem: The number of partitions of 12 into parts of size at most 4 (order of parts does not matter) is what value?
- Problem: The longest palindromic subsequence of "character" has what length?
- Problem: Ropes of lengths 4, 3, 2 and 6 are joined pairwise; joining two ropes costs the sum of their lengths, and the next join uses the…