Data Structures & AlgorithmsVery hardCodeforces Div2 D · TCS NQT
What is the length of the shortest contiguous substring of "xaybzcabbc" that contains "abc" as a SUBSEQUENCE (the letters appear in order, not necessarily next to each other)?
- A. 3
- B. 6
- C. 4
- D. 5
Correct answer: C. 4
For each start, greedily match the pattern letters in order and stop as soon as the last letter is matched; the minimum over starts is the answer. Requiring the letters only to appear in any order (a set check) finds a shorter window that does not respect the order.
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 index triples i < j < k in "abacbab" spell a palindrome of length 3, meaning s[i] = s[k]? (The middle letter is unrestricted.)
- What is the smallest integer x ≥ 100 whose binary representation contains exactly 4 ones?
- Items of sizes [4, 8, 1, 4, 2, 1] must be packed into bins of capacity 10 with no bin over capacity. What is the minimum number of bins…
- How many binary strings of length 8 contain no two adjacent 1s and an EVEN number of 0s?
- The string "abaccbbca" is split into contiguous palindromic pieces. A piece of length L costs L². What is the minimum total cost?
- What is the maximum sum of a contiguous subarray of [4, -1, 2, 2, 5, -3, 4, 1] that contains at most 2 distinct values?