Data Structures & AlgorithmsHardGATE CS · Codeforces Div 2

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

  1. A. 2
  2. B. 6
  3. C. 3
  4. D. 512

Correct answer: A. 2

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

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic