Data Structures & AlgorithmsHardCodeforces Div2 D · TCS NQT
Let t = "ABCC" (its letters may repeat). What is the length of the shortest substring of "ADOBECODEBANCXY" that contains every letter of t with at least the required multiplicity?
- A. 8
- B. 4
- C. 9
- D. 7
Correct answer: A. 8
Two pointers with a need-counter: expand right until all demands are met, then shrink left while still valid, recording the smallest width. Ignoring multiplicities (checking only distinct letters) finds a shorter window that fails the count requirement.
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
- Among all cyclic rotations of "bcabca" (there are n = 6 of them, including the original), what is the 0-based index i of the…
- What is the minimum number of characters that must be inserted at the FRONT of "abaccabb" to make the whole string a palindrome?
- How many contiguous subarrays of [3, 4, -7, 1, 3, 3, 1, -4, 2] have sum exactly 7? Negative numbers are present.
- In "swissmississippi", what is the 0-based index of the first character that appears exactly once in the whole string?
- What is the length of the longest substring of "eceeebbaccbbaaceddccc" that contains AT MOST two distinct letters?
- In the list ['listen', 'silent', 'enlist', 'google', 'gooegl', 'cat', 'act', 'tac', 'dog'], how many unordered pairs of different…