Data Structures & AlgorithmsModerate
How many NON-EMPTY subsequences of 2 3 4 5 6 8 (position subsets) have a product congruent to 1 modulo 7?
- A. 12
- B. 0
- C. 11
- D. 10
Correct answer: C. 11
Track the residue of the product mod 7 as a DP over the items; the target residue 1 is distinct from residue 6 (which equals −1). The empty subsequence has an empty product of 1, so it must be excluded explicitly.
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 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…
- For 2 3 5 6 4 1 3, let Pi be the product of A[0..i] modulo 7 and Si the product of A[i+1..n−1] modulo 7. How many indices i with 0 ≤ i ≤…