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

A subset-sum question has n = 40 values. Splitting them into two halves of 20, how many subset sums must be enumerated for ONE half?

  1. A. 1048576
  2. B. 1099511627776
  3. C. 549755813888
  4. D. 2097152

Correct answer: A. 1048576

Each half has 20 elements and therefore 2^20 = 1,048,576 subsets. Enumerating all 2^40 subsets is what meet-in-the-middle avoids; the two sorted half-lists then combine with a two-pointer pass.

More Coding Interview Problems questions

Exams that ask this topic