Split Array With Minimum Difference
You are given an integer array nums.
Split the array into exactly two subarrays, left and right, such that:
leftis strictly increasing.rightis strictly decreasing.
Return the minimum possible absolute difference between the sums of left and right. If no valid split exists, return -1.
Example 1
Input
nums = [1,3,2]Output
2The valid splits have absolute differences 4 and 2, so the minimum absolute difference is 2.
Example 2
Input
nums = [1,2,4,3]Output
4The valid splits have absolute differences 4 and 4, so the minimum absolute difference is 4.
Constraints
- 2 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5