Data Structures & AlgorithmsHardTCS NQT · GATE CS

How many non-empty subsets of [2, 4, 6, 8, 10, 12, 3] (chosen by position) have a sum of exactly 25?

  1. A. 5
  2. B. 7
  3. C. 6
  4. D. 4

Correct answer: A. 5

Count subsets by sum with a subset-sum DP over the target: dp[s] = number of subsets reaching s, updated once per element. The array has only one odd value, so an odd total needs an odd number of odd elements, which is a useful check on the answer. Counting only subsets with sums 24 or 26 misses the target.

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

Exams that ask this topic