Partition Array Into Two Arrays to Minimize Sum Difference
You are given an integer array nums of 2 * n integers. You need to partition nums into two arrays of length n to minimize the absolute difference of the sums of the arrays. To partition nums, put each element of nums into one of the two arrays.
Return the minimum possible absolute difference.
Example 1
Input
nums = [3,9,7,3]Output
2One optimal partition is [3, 9] and [7, 3], whose sums differ by 2.
Example 2
Input
nums = [-36,36]Output
72One optimal partition is [-36] and [36], whose sums differ by 72.
Constraints
- 1 <= n <= 15
- nums.length == 2 * n
- -10^7 <= nums[i] <= 10^7