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

How many subsets (including the empty subset) of the values [2, 3, 5, 7, 11, 13, 4, 6] have a sum between 10 and 20 inclusive?

  1. A. 71
  2. B. 62
  3. C. 67
  4. D. 57

Correct answer: C. 67

Meet in the middle: enumerate sums of each half, sort one list, and count with two binary searches per value to get the number in the range. Subsets whose sum is exactly 20 must be included, which the strict upper bound drops.

More Coding Interview Problems questions

Exams that ask this topic