Mid/SeniorArrayPrefix Sum

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 + 1 elements is greater than or equal to the sum of the last n - i - 1 elements.
  • 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
Inputnums = [10,4,-8,7]
Output2
Splits 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
Inputnums = [2,3,1,0]
Output2
Splits 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

Asked at 7 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate