Data Structures & AlgorithmsHardGATE CS · Codeforces Div2 C

How many non-empty subsets of [3, 5, 6, 7, 9] (chosen by position) have a sum divisible by 4?

  1. A. 8
  2. B. 7
  3. C. 5
  4. D. 32

Correct answer: B. 7

A subset-sum DP over residues modulo k counts subsets with each remainder; the answer is the count for remainder 0 with the empty subset removed. Forgetting to exclude the empty set, which has sum 0, shifts the answer by one.

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

Exams that ask this topic