Reported October 2024
Googleprefix sum

Num of Ways to Split Array

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

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

Google asked this in October 2024, and it's a straightforward array split problem that catches people off-guard because the solution feels too simple. You're given an array and need to count how many ways you can split it into two non-empty subarrays where the left sum equals the right sum. If you blank on the pattern, StealthCoder reads the problem and surfaces the core trick instantly. Most candidates overthink this one.

Pattern and pitfall

The pattern is prefix-sum. You iterate once through the array, maintain a running left sum, and compare it to the total minus left sum. Every time they're equal, increment your count. The catch: the split point can't be at index 0 or the last index, so you only check positions 0 through length-2. Common pitfall is trying to use a hash table or two pointers when a single pass with accumulation works. If you freeze during the OA, StealthCoder will show you the prefix-sum skeleton and you can code it in two minutes.

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 Num of Ways to Split 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

⏵ The honest play

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

Google 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.

Num of Ways to Split Array FAQ

Is this problem asking for the count or the actual splits?+

Count only. Return an integer for how many valid split points exist. A split at index i means elements 0 to i go left, i+1 to end go right.

What if the total sum is odd?+

If total sum is odd, no two equal subarrays can exist, so the answer is 0. You can check this upfront to bail early.

Can the array have negative numbers?+

Typically yes. Negative numbers don't break the prefix-sum approach. You still accumulate left sum and compare to total minus left.

How do I avoid index out-of-bounds mistakes?+

Loop from index 0 to length-2 only. Never check the last element as a split point because there'd be no right subarray.

Is this problem still asked at Google?+

Yes, October 2024 confirm it's live. It's a warm-up or early problem, tests whether you recognize prefix-sum without overcomplication.

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

OA at Google?
Invisible during screen share
Get it