Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

Array A = [9, 4, 4, 8, 1, 7, 2] (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 14.

  1. A. 1909
  2. B. 128
  3. C. 45
  4. D. 6

Correct answer: D. 6

Enumerating all subsets of indices gives 6 with sum 14. Allowing each value to be reused, as in the coin-change count, gives 1909.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic