Data Structures & AlgorithmsModerateICPC regional · Amazon SDE OA

How many non-empty subsets of [1, 2, 3, 4, 6] have a sum divisible by 3?

  1. A. 12
  2. B. 31
  3. C. 11
  4. D. 2

Correct answer: C. 11

Residues mod 3 are 1, 2, 0, 1, 0; a residue DP over the 32 subsets gives 12 with sum ≡ 0, including the empty set, so 11 non-empty ones. Forgetting to remove the empty set gives 12, 31 counts every non-empty subset, and 2 counts only the singletons 3 and 6.

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

Exams that ask this topic