330. Partition a set into two subsets with minimum absolute sum difference
Given an array arr of n integers, partition the array into two subsets such that the absolute difference between their sums is minimized.
Example 1:
Input: arr = [1, 7, 14, 5]
Output: 1
Explanation: The array can be partitioned as [1, 7, 5] and [14], with an absolute difference of 1.
Example 2:
Input: arr = [3, 1, 6, 2, 2]
Output: 0
Explanation: The array can be partitioned as [3, 2, 2] and [6, 1], with an absolute difference of 0.
Now Your Turn!
Pick the correct output for the given inputInput: arr = [2, 2, 2, 9]
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 ≤ n * sum of array elements ≤ 106
- 0 < arr[i] <= 104