Number of Ways to Split Array
You are given a 0-indexed integer array nums of length n.
nums contains a valid split at index i if the following are true:
- The sum of the first
i + 1elements is greater than or equal to the sum of the lastn - i - 1elements. - There is at least one element to the right of
i; that is,0 <= i < n - 1.
Return the number of valid splits in nums.
Example 1
Input
nums = [10,4,-8,7]Output
2Splits at indices 0 and 1 are valid because their left sums are greater than or equal to their right sums, while the split at index 2 is not valid.
Example 2
Input
nums = [2,3,1,0]Output
2Splits at indices 1 and 2 are valid because their left sums are greater than or equal to their right sums.
Constraints
- 2 <= nums.length <= 10^5
- -10^5 <= nums[i] <= 10^5