You're given an integer array nums of 2n integers. Your task is to partition this array into two separate arrays, each containing exactly n elements, such that the absolute difference between the sums of these two arrays is minimized.
Think of it as trying to balance two scales as evenly as possible - you want to distribute the weights (numbers) so that neither side is much heavier than the other.
Goal: Find the minimum possible absolute difference between the sums of the two partitioned arrays.
Example: If nums = [3,9,7,3], you could partition it as [3,7] and [9,3], giving sums of 10 and 12 respectively, for a difference of 2.
Input & Output
Visualization
Time & Space Complexity
We generate 2^n subsets for each half, then for each subset in left half, we binary search in right half
We store all possible subset sums for both halves
Constraints
- 2 โค nums.length โค 20
- nums.length is even
- -106 โค nums[i] โค 106
- The array contains exactly 2n elements