Data Structures & AlgorithmsModerateGATE CS · TCS NQT

How many DISTINCT values can the sum of a subset of [1, 2, 4, 8, 3] take? The empty subset (sum 0) is included.

  1. A. 32
  2. B. 18
  3. C. 19
  4. D. 21

Correct answer: C. 19

Maintain the set of reachable sums: each new number x adds the shifted copy {s + x}. Counting subsets instead of sums overcounts whenever two different subsets share the same total.

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

Exams that ask this topic