Data Structures & AlgorithmsModerate
How many NON-EMPTY subsequences of 1 2 3 5 6 8 9 (subsets chosen by position) have (maximum − minimum) ≤ 2?
- A. 16
- B. 15
- C. 11
- D. 8
Correct answer: B. 15
A subsequence is determined by its chosen positions, so every subset of the array is a candidate; the spread test then decides. Including the empty set, using a strict bound, or dropping singletons each change the total.
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 NON-EMPTY subsequences of 2 3 4 5 6 8 (position subsets) have a product congruent to 1 modulo 7?
- How many subsequences of EXACTLY three elements of 1 2 3 4 5 6 7 8 (chosen by position) have an EVEN sum?
- In the string "aabbaab", how many pairs of positions i < j form the subsequence 'ab' (S[i] = 'a' and S[j] = 'b')?
- How many index triples i < j < k in "aabbccabc" spell the subsequence 'abc' (characters need not be adjacent)?
- How many subsets of {1, 2, ..., 9} have sum exactly 10 (the empty set is not counted, and each value is used at most once)?
- How many contiguous subarrays of length at least 2 of 3 1 4 2 5 contain an EVEN number of inversions (pairs i < j inside the subarray with…