Reported July 2026
Salesforceprefix sum

Good Ways to Split an Array

Reported by candidates from Salesforce's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Salesforce OA. Under 2s to a working solution.
Founder's read

The Salesforce OA reported in July 2026 hides a prefix sum array inside a simple-looking split problem. You get non-negative integers, cut them into three non-empty contiguous chunks, and count the cuts where the middle sum doesn't beat the outer two combined. Brute force over both cut points is O(n^2) and it'll time out. The prefix array turns every subarray sum into a subtraction, and that's the whole game. If you blank on the setup during the live assessment, StealthCoder runs invisibly as a safety net and shows the approach while you type.

The problem

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[]) → int

Examples
Example 1
nums = [1,2,3,4]
return = 3
The 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.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Build prefix sums P where P[i] is the sum of the first i elements, and let T be the total. Fix the first cut i, so S1 = P[i]. For a second cut j, S2 = P[j] - P[i] and S3 = T - P[j]. The condition S2 <= S1 + S3 becomes 2*P[j] <= T + P[i]. Because nums are non-negative, P is non-decreasing, so the valid j values form a contiguous range. Binary search for the largest j satisfying the inequality, or slide a two-pointer, and clamp j to at least i+1 and at most n-1 so S3 stays non-empty. Add the count of valid j for each i. Pitfalls: forgetting the non-empty constraint, off-by-one on the range ends, and applying the modulo to the final sum only. Sums can get large, so use 64-bit integers in languages that overflow. In the live OA, StealthCoder is the hedge if the inequality rearrangement slips your mind.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Good Ways to Split an Array cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as ways to split array into three subarrays. If you have time before the OA, drill that.

⏵ The honest play

You've seen the question. Make sure you actually pass Salesforce's OA.

Salesforce reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Good Ways to Split an Array FAQ

What's the trick in Good Ways to Split an Array?+

Prefix sums plus the monotonic property. Since values are non-negative, prefix sums never decrease, so for each first cut the valid second cuts form one contiguous range. Find its edge with binary search or a moving pointer instead of testing every pair.

How hard is this one really?+

Medium. The idea is short once you rewrite the condition as 2*P[j] <= T + P[i]. The difficulty is in the boundaries, keeping all three parts non-empty, and not sinking time into an O(n^2) approach that fails on large inputs.

Binary search or two pointers?+

Both work. Two pointers give O(n) because the right boundary only moves forward as i grows. Binary search is O(n log n) and easier to get right under pressure. If you're nervous, pick binary search and test the edges carefully.

Where do people lose points on this problem?+

Off-by-one errors on the non-empty rule, missing the modulo 10^9 + 7, and integer overflow on big sums. Test tiny arrays like length 3 and the example [1,2,3,4], which should return 3.

How do I prepare for this in 48 hours?+

Write prefix-sum code from scratch until it's automatic. Then do two or three problems where a monotonic prefix array lets you binary search a range. Practice rewriting a sum condition into an inequality on prefix values, since that step is what this question tests.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Salesforce.

OA at Salesforce?
Invisible during screen share
Get it