Equal Sum Split After One Removal
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
The mistake that sinks a first attempt on this Google OA, reported in September 2026, is brute force: try every removal, then rescan for a split. That's O(n^2) and n goes up to 200,000, so it dies on the big tests. The real problem is a prefix sum puzzle with a hash lookup. All values are positive, which makes the math clean. If you blank on the structure, StealthCoder runs invisibly during the live assessment as a safety net. But the idea is short enough to hold in your head tonight.
The problem
Given an array nums of positive integers, remove exactly one element while preserving the relative order of all remaining elements. Return true if the remaining sequence can be split into two non-empty contiguous subarrays with equal sums. Otherwise, return false. Removal and split rules You may choose any one index to remove. After the removal, every remaining element must belong to exactly one of the two subarrays. Both subarrays must be contiguous in the remaining sequence. Function canSplitAfterRemoval(nums: int[]) → boolean Examples Example 1 nums = [1,2,3,3] return = true Remove the last 3. The remaining sequence is [1,2,3], which splits into [1,2] and [3]. Both sums are 3. Example 2 nums = [1,2,5] return = false Every removal leaves two unequal single-element subarrays, so no valid split exists. Example 3 nums = [2,1,1,2] return = true Remove the first 2. The remaining sequence [1,1,2] splits into [1,1] and [2], each with sum 2. Constraints 3 <= nums.length <= 2 * 10^5 1 <= nums[i] <= 10^9
Reported by candidates. Source: FastPrep
Pattern and pitfall
Let total be the sum. After removing nums[i], the remaining sum is total - nums[i], and it must be even, so the target for each half is (total - nums[i]) / 2. The trick: the split point is either left of i or right of i. Scan left to right keeping a prefix sum and a hash set of prefix sums seen so far. At index i, if the left half ends before i, you need a prefix equal to target in the set. If the split lands after i, the left part is prefix up to j minus nums[i], so you need prefix(i) + target + nums[i] to appear later. Run a second pass from the right, or a suffix set. Pitfalls: both halves must be non-empty, so reject empty prefixes, and use 64-bit sums since values reach 10^9 times 2*10^5. Positivity means prefix sums are strictly increasing, so a binary search also works. StealthCoder is the hedge if the indexing gets tangled mid-assessment.
If you see this problem in your OA tomorrow, the play is to recognize the pattern in 30 seconds. StealthCoder buys you that recognition.
You can drill Equal Sum Split After One Removal 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 passed his OA cold and still thinks the filter is broken.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Built by an Amazon engineer who passed his OA cold and still thinks the filter is broken. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Equal Sum Split After One Removal FAQ
What's the trick for Equal Sum Split After One Removal?+
Use prefix sums and a hash set. For each removed index, the remaining total must be even, and each half needs exactly half of it. Then check whether a prefix with the needed sum exists on the correct side of the removed element. That gives O(n) instead of O(n^2).
How hard is this Google OA question really?+
Medium, with a hard feeling at first. The idea is small, but the off-by-one cases around the removed index trip people up. If you're comfortable with prefix sums and sets, it's a 20 to 30 minute problem once you see the target formula.
Why does brute force fail here?+
With n up to 200,000, removing each element and rescanning for a split is about 4 * 10^10 operations. It times out. You need a single pass that reuses prefix sums so each removal is answered in constant time.
What edge cases should I test?+
Test the minimum length of 3, where removal leaves two single elements. Test an odd remaining sum, which must fail. Test a split where the removed element sits inside the left half versus the right half. Also test large values to catch 32-bit overflow.
How do I prepare for this in 48 hours?+
Redo prefix sum plus hash set problems like subarray sum equals k and partition equal subset checks. Practice deriving the target on paper, then code the left-side and right-side cases separately. Use long integers from the start so overflow never bites.