Data Structures & AlgorithmsModerateGATE CS · ICPC regional
What is the number of distinct subsequences (including the empty one) of the string abab?
- A. 13
- B. {C+7}
- C. 12
- D. 15
Correct answer: C. 12
Count distinct strings, not index choices: this set includes the empty string, the single letters, and repeated patterns such as ab and aba collapsing from different index sets.
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
- Starting at value 1, apply the operations x -> 2x, then x -> x + 3, alternating (double, add 3, double, add 3, ...), for 6 operations in…
- A matrix has rows [1, 2, 3], [4, 5, 6], [7, 8, 9]. The matrix is transposed and then each row is reversed. What is the element in row 0…
- How many subsequences of length 3 of the string abcabc are palindromes (distinct index choices count separately)?
- A queue holds 1 to 6 in order. The front element is moved to the back, then the front is removed, repeated until one element remains…
- What is the number of integer pairs (x, y) with 1 <= x <= y <= 20 for which gcd(x, y) = 1 and x + y is even?
- How many elements of the array [6, 12, 18, 24, 30] are divisible by at least one element that appears before them in the array?