Data Structures & AlgorithmsHard

How many NON-EMPTY subsets of {1, 2, 3, 4, 5, 6} have a sum that is a prime number?

  1. A. 32
  2. B. 22
  3. C. 19
  4. 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.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic