Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Array A = [4, 3, 9, 3, 3, 9, 7] (indices 0 to 6). Count the non-empty subsets of positions (each position used at most once, subsets not ordered) whose values add up to exactly 9.

  1. A. 128
  2. B. 2
  3. C. 3
  4. D. 14

Correct answer: C. 3

Enumerating all subsets of indices gives 3 with sum 9. Allowing each value to be reused, as in the coin-change count, gives 2.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic