1228. Partition Into Two Arrays to Minimize Sum Difference

HardDynamic ProgrammingBitmask DP

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

Input: JSON {nums}.

Output: Integer — the minimum sum difference.

Examples

Example 1
Input: {"nums":[3,9,7,3]}
Output: 2
Explanation: [3,7] and [9,3] differ by 2.
Example 2
Input: {"nums":[36,36]}
Output: 0
Explanation: Equal halves.
Example 3
Input: {"nums":[1,2]}
Output: 1
Explanation: Difference of 1.

Constraints

Asked by

AmazonGoogleMicrosoftMetaAdobe
Solve this problem in the editor →