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

Can the numbers 1 through 20 be split into two groups with equal sums? Answer 1 if yes and 0 if no, computed with a subset-sum DP over bits.

  1. A. 0
  2. B. 2
  3. C. 1
  4. D. 3

Correct answer: C. 1

The total is 210, which is even, and a bitset subset-sum DP over the values 1..20 reaches 105, so a split exists. Checking only parity would give the same answer here, but the true test is reachability of half the total.

More Coding Interview Problems questions

Exams that ask this topic