Data Structures & AlgorithmsHardProduct company OA

The set [3, 9, 7, 3, 11] is split into two subsets so that the absolute difference of their sums is as small as possible (subset-sum DP over achievable sums). What is the minimum difference?

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

Correct answer: A. 1

The total is 33 (odd), so 0 is impossible. Reachable sums include 16 (9 + 7, or 3 + 3 + … ) and 17 (3 + 3 + 11), giving 16 vs 17 → difference 1. Placing items greedily (each into the currently lighter side) is not guaranteed to find this, which is why the subset-sum DP over all reachable sums is used.

More Trees, Graphs, Recursion and Dynamic Programming questions

Exams that ask this topic