Data Structures & AlgorithmsVery hardGATE CS · ICPC regional
What is the length of the shortest substring of aabdecbcaeb that contains every character of abc (with multiplicity: at least one of each of a, b and c)?
- A. 3
- B. 4
- C. 2
- D. 5
Correct answer: A. 3
Expand the right boundary until all required letters are covered, then shrink from the left while coverage holds. Track coverage with counts, not a set, so repeated letters are handled.
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
- For the string bcabca, let a rotation be the string obtained by moving a prefix of some length to the end. If rotations are indexed from 0…
- How many occurrences of the pattern aba are found in the string abababa when occurrences may overlap?
- What is the length of the longest palindromic subsequence of the word character?
- A backspace text editor reads the string a##b#cd# where each # deletes the previous character if one exists. How many characters remain in…
- How many non-empty contiguous subarrays of [6, 10, 15, 7] have gcd equal to 1?
- What is the sum of gcd(a[i..j]) over all contiguous subarrays of [4, 6, 8, 12]?