#1712
Ways to Split Array Into Three Subarrays
expert · 1075 · lc medium +32 · verified · 34.2% accepted · 1,504 likes · top 12%
Description
A split of a non-negative integer array nums into three non-empty contiguous subarrays left, mid, and right is good when sum(left) <= sum(mid) <= sum(right). Return the total number of good splits modulo 109 + 7.
Example 1:
Input: nums = [1,1,1]
Output: 1
Explanation: The only good way to split nums is [1] [1] [1].
Example 2:
Input: nums = [1,2,2,2,5,0]
Output: 3
Explanation: There are three good ways of splitting nums:
[1] [2] [2,2,5,0]
[1] [2,2] [2,5,0]
[1,2] [2,2] [5,0]
Example 3:
Input: nums = [3,2,1]
Output: 0
Explanation: There is no good way to split nums.
Code
1
2
3