Data Structures & AlgorithmsVery hardProduct company OA · Amazon/Microsoft-style OA

How many subsets of {1, 2, ..., 12} have a sum of exactly 20?

  1. A. 48
  2. B. 43
  3. C. 51
  4. D. 45

Correct answer: D. 45

Split {1..12} into {1..6} and {7..12}, enumerate the 64 subset sums of each half, and count matching pairs with a counter. The counts are over subsets, so different subsets with the same sum are all counted.

More Coding Interview Problems questions

Exams that ask this topic