Data Structures & AlgorithmsHard
How many NON-EMPTY subsets of {1, 2, 3, 4, 5, 6} have a sum that is a prime number?
- A. 32
- B. 22
- C. 19
- D. 23
Correct answer: B. 22
List the 63 non-empty subsets and test each sum for primality; 1 is not prime, so the sum 1 never qualifies. Parity, dropping singletons, or the empty set each change the count.
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 index pairs i < j in 1 2 4 8 9 3 12 6 have a product A[i]·A[j] that is a perfect square?
- How many index triples i < j < k in 2 5 3 8 6 9 4 have A[i] < A[j] < A[k] AND an EVEN total sum?
- For counting subsequences equal to a fixed pattern (like 'abc'), why must the DP update the longer prefixes first?
- Why does the count of subsequences (index subsets) with sum divisible by m use a DP over residues rather than enumerating subsets?
- Why is an XOR-zero subset family structured like a vector space over the two-element field?
- When counting subarrays with sum in a range [L, R] for an array with zeros, why can a single subarray start be counted many times with a…