1712. Ways to Split Array Into Three Subarrays

Medium

1.2K

96

A split of an integer array is **good** if:

- The array is split into three
**non-empty**contiguous subarrays - named`left`

,`mid`

,`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 `10`^{9 }+ 7

.

**Example 1:**

Input:nums = [1,1,1]Output:1Explanation:The only good way to split nums is [1] [1] [1].

**Example 2:**

Input:nums = [1,2,2,2,5,0]Output:3Explanation: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:0Explanation:There is no good way to split nums.

**Constraints:**

`3 <= nums.length <= 10`

^{5}`0 <= nums[i] <= 10`

^{4}

Accepted

28.6K

Submissions

87.5K

Acceptance Rate

32.7%

Seen this question in a real interview before?

1/4

Yes

No

Discussion (0)

Related Topics

Copyright ©️ 2023 LeetCode All rights reserved