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

The values [7, 4, 9, 2, 6, 5] are distributed among two groups (each value goes to exactly one group, any group may be empty). What is the smallest possible absolute difference between the two group sums?

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

Correct answer: D. 1

Enumerating every split of the six values gives the exact minimum: the best split puts one group's sum as close as possible to half the total. Comparing against the total sum alone ignores the split.

More Coding Interview Problems questions

Exams that ask this topic