1151. Minimum Subset Sum Difference

EasyDynamic Programming0/1 Knapsack

Given an array nums of non-negative integers, partition it into two subsets to minimize the absolute difference of their sums. Return that minimum difference. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the minimum subset-sum difference.

Examples

Example 1
Input: {"nums":[1,6,11,5]}
Output: 1
Explanation: [1,5,6] vs [11].
Example 2
Input: {"nums":[1,2,3,9]}
Output: 3
Explanation: [1,2,3] vs [9].
Example 3
Input: {"nums":[7]}
Output: 7
Explanation: One subset is empty.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →