Data Structures & AlgorithmsHardProduct company OA · Amazon/Microsoft-style OA

How many subsets (including the empty subset) of {1, 2, ..., 10} have a sum divisible by 3?

  1. A. 344
  2. B. 343
  3. C. 345
  4. D. 341

Correct answer: A. 344

Count by DP over the sum modulo 3: each element either skips or shifts the residue, starting at residue 0 for the empty set. Excluding the empty set is the usual mistake, since its sum 0 is divisible by 3.

More Coding Interview Problems questions

Exams that ask this topic