Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many subsets of [2, 3, 5, 7, 4, 1, 6, 8] (chosen by position, the empty set excluded) have a sum of exactly 10?

  1. A. 9
  2. B. 16
  3. C. 8
  4. D. 7

Correct answer: C. 8

Count with dp[s] = number of subsets reaching sum s, processing items one at a time and iterating sums downwards. The empty subset contributes to dp[0] and must not be counted when the target is positive, so the raw dp value is one more than the answer when the target 0 path is involved.

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

Exams that ask this topic