Number of Ways to Split Array

Medium Topics Company Tags

Count the positions where nums can be divided into a nonempty prefix and a nonempty suffix such that the prefix sum is at least the suffix sum. Return the number of valid positions. Both parts must contain at least one element.

Example 1:

Input: nums = [0,0]

Output: 1

Explanation: The only split is [0] and [0]. The left sum equals the right sum, so it is valid.

Example 2:

Input: nums = [1,1]

Output: 1

Explanation: The only split is [1] and [1]. Both sums are 1, so there is one valid split.

Example 3:

Input: nums = [1,2]

Output: 0

Explanation: The only split is [1] and [2]. The left sum is smaller than the right sum, so this split is invalid.

Constraints:

  • 2 <= nums.length <= 100000
  • -100000 <= nums[i] <= 100000


Topics

Company Tags

Please upgrade to NeetCode Pro to view company tags.