Imagine you have an array of 3 * n integers, and you're challenged to create the most balanced split possible. Your mission is to remove exactly n elements, then divide the remaining 2 * n elements into two equal groups.
The twist? You want to minimize the absolute difference between the sums of these two groups. The first n elements (in order) form the first group, and the next n elements form the second group.
Goal: Find the minimum possible value of sum_first - sum_second after strategically removing n elements.
Example: If nums = [3,1,2,4,6,5] and n = 2, you could remove [3,6] to get [1,2,4,5]. Then split into first group [1,2] (sum=3) and second group [4,5] (sum=9), giving difference 3-9 = -6.
Input & Output
Constraints
- nums.length == 3 * n
- 1 โค n โค 105
- 1 โค nums[i] โค 105
- The array always has exactly 3n elements