Ways to Split Array Into Three Subarrays

A split of an integer array is good if:

  • The array is split into three non-empty contiguous subarrays named left, mid, and right, respectively from left to right.
  • The sum of the elements in left is less than or equal to the sum of the elements in mid, and the sum of the elements in mid is less than or equal to the sum of the elements in right.

Given nums, an array of non-negative integers, return the number of good ways to split nums. As the number may be too large, return it modulo 10^9 + 7.

Example 1
Inputnums = [1,1,1]
Output1
The only good way to split nums is [1] [1] [1].
Example 2
Inputnums = [1,2,2,2,5,0]
Output3
There are three good ways of splitting nums: [1] [2] [2,2,5,0], [1] [2,2] [2,5,0], and [1,2] [2,2] [5,0].

Constraints

  • 3 <= nums.length <= 10^5
  • 0 <= nums[i] <= 10^4

Asked at 3 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