Data Structures & AlgorithmsHard

What is the smallest positive integer that CANNOT be written as the sum of some subset (each element used at most once) of the sorted array [1, 1, 3, 4, 10, 25]?

  1. A. 19
  2. B. 20
  3. C. 25
  4. D. 45

Correct answer: B. 20

Scan the sorted array keeping the reachable range [0..R]: a value a ≤ R+1 extends it to R+a, and a value larger than R+1 leaves R+1 unreachable, since all later values are bigger. Here the reach stops at 19, so 20 is the answer.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic