Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many non-empty subsets of [2, 3, 4, 5, 6] (chosen by position) have a sum that is a prime number?

  1. A. 12
  2. B. 15
  3. C. 10
  4. D. 31

Correct answer: A. 12

Enumerate all subsets with a bitmask (2⁵ = 32 of them) and test each sum for primality. Forgetting that a sum can equal a prime from a single element, or counting the empty subset, shifts the total.

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

Exams that ask this topic