Problem · Array
Good Ways to Split an Array
Learn this problemProblem statement
You are given an array of non-negative integers nums. Split it into three non-empty contiguous subarrays A1, A2, and A3.
Let S1, S2, and S3 be their sums. Count the number of splits such that S2 <= S1 + S3. Return the answer modulo 10^9 + 7.
Function
countGoodSplits(nums: int[]) → intExamples
Example 1
nums = [1,2,3,4]return = 3The valid split points are after [1] | [2] | [3,4], [1] | [2,3] | [4], and [1,2] | [3] | [4]. All three satisfy S2 <= S1 + S3.
The source shared the rule but did not include this exact sample. FastPrep added this small example so the behavior can be checked directly.