Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
What is the length of the shortest substring of "aabcbcdbca" that contains every distinct letter appearing in the whole string at least once?
- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
A two-pointer window with letter counts: expand until all distinct letters are present, then shrink from the left while they remain. The answer is the smallest such width. Counting the distinct letters gives only the lower bound.
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 contiguous subarrays of [4, 2, 3, 1, 6, 5, 7, 9] satisfy max − min = (length of the subarray) − 1? Count every such subarray…
- What is the length of the longest substring of "bbaacabaacb" that contains EXACTLY two letters 'a'?
- Choose exactly 4 elements of [6, 1, 9, 4, 7, 2, 8, 5] (by position) such that no two chosen positions are adjacent. What is the maximum…
- How many permutations of 1, 2, 3, 4, 5 have exactly 3 inversions (pairs of positions i < j with p[i] > p[j])?
- What is the minimum number of positive perfect cubes (1, 8, 27, ...) whose sum is exactly 31? Repeats are allowed.
- How many substrings of "abacaxayaba" are palindromes of ODD length at least 3?