Data Structures & AlgorithmsVery hardGATE CS · Codeforces Div2 B
How many substrings of abcabcbb contain no repeated character?
- A. 18
- B. 20
- C. 16
- D. 23
Correct answer: A. 18
All substrings of length 1 qualify, plus the distinct-letter stretches of length 2 and 3. Counting by the sliding window's maximum length alone misses the shorter valid 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
- Evaluate the postfix (reverse Polish) expression 5 1 2 + 4 + 3 -. What is the value?
- Array [5, 2, 8, 1, 9, 3] is processed in one left-to-right pass: each node is deleted if its value is strictly greater than the value of…
- A singly linked list holds 1, 2, 3, 4, 5, 6, 7. Adjacent pairs are swapped in one pass (node 1 with 2, node 3 with 4, and so on; an…
- How many index pairs i < j in the array [1, 2, 3, 1, 2, 3] make a[i] a[j] = 6?
- How many contiguous subarrays of [2, -2, 3, 1, -4, 2, -1] have sum 0?
- How many index pairs i < j in the array [1, 3, 5, 7, 2, 6, 8] have a[i] + a[j] equal to a power of 2?