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

From the values [5, 12, 7, 3, 9, 14, 2, 8], what is the minimum number of values you must choose so that their sum is at least 25? Meet in the middle can find the best sums of each half and combine them.

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

Correct answer: C. 2

Check subsets by size, using meet in the middle over the halves to find the best sum for each size. The smallest size whose best sum reaches 25 is 2, since 14 + 12 = 26 is the strongest pair.

More Coding Interview Problems questions

Exams that ask this topic