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

Using each of the values 1, 2, 5, 9 and 20 at most once, which is the smallest positive integer that CANNOT be written as the sum of some subset?

  1. A. 5
  2. B. 3
  3. C. 4
  4. D. 8

Correct answer: C. 4

Subset sums of the sorted values extend contiguously as long as each new value is at most one more than the sum so far; the first gap shows the missing integer. Testing only single values or only prefix sums stops the search too early.

More Coding Interview Problems questions

Exams that ask this topic