Data Structures & AlgorithmsHardGATE CS · TCS NQT

How many non-empty subsets of [3, 1, 4, 2, 5] (chosen by position) have a sum between 4 and 7 inclusive?

  1. A. 14
  2. B. 11
  3. C. 9
  4. D. 8

Correct answer: B. 11

Subset-sum counting: enumerate subsets or use a DP over sums and add the counts for every target in the range. The bounds are inclusive, so off-by-one at R or L changes the answer.

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

Exams that ask this topic