Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA
How many distinct subsequences (including the empty string) does "aab" have?
- A. 5
- B. 3
- C. 6
- D. 2
Correct answer: C. 6
Distinct strings: '', a, b, aa, ab, aab = 6; the two ways to pick one a collapse into one string. Forgetting the empty string gives 5, 3 is the length and 2 the number of distinct letters.
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 pairs (a, b) with 1 <= a <= b <= 20 satisfy a b = 36?
- For [4, 1, 3, 2, 5], each index i gets the index of its previous strictly greater element (or -1 if none). What is the sum of these values…
- How many windows of size 3 in [5, 2, 7, 3, 1, 6, 4] have their minimum exactly at the middle position?
- Five lectures are the half-open intervals [1,2), [2,5), [4,6), [5,8), [7,9). How many lectures can be attended without overlap (touching…
- How many index pairs i < j in "aabb" give a palindromic subsequence of length 2 (that is, s[i] = s[j])?
- How many distinct value pairs (x, y) with x < y satisfy x + y = 10 among the values of [1, 2, 3, 4, 5, 6, 7, 8, 9, 5]?