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.
More Salesforce problems
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026
- Key Teams in TreeOA · Seen Mar 2026