Data Structures & AlgorithmsHard
How many DISTINCT non-empty strings can be formed as subsequences (characters taken in order, not necessarily adjacent) of "abab"?
- A. 11
- B. 15
- C. 10
- D. 12
Correct answer: A. 11
Count distinct strings, not index choices: repeated letters create identical subsequences that must be counted once. Counting index subsets gives 2^n − 1, and counting contiguous substrings gives another number.
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
- Arrange the numbers 3 30 34 5 9 in some order and concatenate their decimal digits. What is the LARGEST number that can be produced?
- From 4 9 1 7 3 8 2, choose positions so that no two CHOSEN positions are adjacent in the array. What is the maximum possible sum of the…
- How many index pairs i < j in 2 7 4 9 6 3 8 have an ODD sum A[i] + A[j] while also satisfying A[i] < A[j]?
- In 3 1 4 1 5 9 2 6 5 3, what is the largest possible index distance j − i between two positions i < j that hold EQUAL values?
- For 3 1 4 1 5 9 2 6 5 3, for each value that appears at least twice, add up the index gaps between consecutive occurrences of that value…
- How many contiguous subarrays of length exactly 3 in 1 2 1 3 3 2 3 1 1 read the same forwards and backwards?