1712. Ways to Split Array Into Three Subarrays Medium

@problem@discussion
#Array#Two Pointers#Binary Search#Prefix Sum



1/**
2 * [1712] Ways to Split Array Into Three Subarrays
3 *
4 * A split of an integer array is good if:
5 * 
6 * 	The array is split into three non-empty contiguous subarrays - named left, mid, right respectively from left to right.
7 * 	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.
8 * 
9 * 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.
10 *  
11 * Example 1:
12 * 
13 * Input: nums = [1,1,1]
14 * Output: 1
15 * Explanation: The only good way to split nums is [1] [1] [1].
16 * Example 2:
17 * 
18 * Input: nums = [1,2,2,2,5,0]
19 * Output: 3
20 * Explanation: There are three good ways of splitting nums:
21 * [1] [2] [2,2,5,0]
22 * [1] [2,2] [2,5,0]
23 * [1,2] [2,2] [5,0]
24 * 
25 * Example 3:
26 * 
27 * Input: nums = [3,2,1]
28 * Output: 0
29 * Explanation: There is no good way to split nums.
30 *  
31 * Constraints:
32 * 
33 * 	3 <= nums.length <= 10^5
34 * 	0 <= nums[i] <= 10^4
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/ways-to-split-array-into-three-subarrays/
40// discuss: https://leetcode.com/problems/ways-to-split-array-into-three-subarrays/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn ways_to_split(nums: Vec<i32>) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_1712() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.