Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

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

  1. A. 13
  2. B. 512
  3. C. 50
  4. D. 127

Correct answer: A. 13

Enumerating all subsets of indices gives 13 with sum 8. Allowing each value to be reused, as in the coin-change count, gives 127.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic