Data Structures & AlgorithmsModerateCodeforces Div2 B · TCS NQT
How many DISTINCT substrings of length exactly 3 does "abcabcbb" contain?
- A. 6
- B. 5
- C. 3
- D. 4
Correct answer: B. 5
A rolling hash or a set over all length-3 windows gives the distinct count, while the number of windows (n − 2) counts repeats. Counting distinct letters answers a different question.
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 "aeixoaeiuxoaeiou" consist only of vowels AND contain all five vowels a, e, i, o, u at least once?
- Consider the pattern-matching algorithms: naive, KMP, Rabin–Karp (polynomial rolling hash), Z-function. Which statement is correct?
- A polynomial rolling hash with a fixed modulus M and random base B is used to compare two different strings of length L. Which statement…
- What is the length of the longest palindromic substring of "bananaracecarbnn"?
- Apply the reversal of the first 4 elements to the queue 1, 2, 3, 4, 5, 6, 7, 8 (front first). What is the element at position 6 of the…
- For the array [1, 3, 2, 4], take the next strictly greater element of each position (-1 if none) and sum these values, ignoring the -1…