Reported December 2024
Microsoftdynamic programming

Three Partition Array

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

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

Microsoft hit you with Three Partition Array in December 2024, and this one's deceptively simple on the surface. You're given an array and need to split it into three contiguous subarrays with equal sum. Sounds straightforward until you realize the constraints or edge cases bite back. Most candidates blank on the state transitions or miss the prefix-sum setup that makes this solvable in one pass. StealthCoder will catch the pattern if your brain locks up during the live OA.

Pattern and pitfall

The trick is prefix sums and DP. If the total sum isn't divisible by 3, return false immediately. Otherwise, you're looking for two partition points where the left third and middle third each sum to total/3. A naive approach checks every pair of indices, which works but is slow. The DP angle: as you scan left to right, track whether you've already found the first partition, then look for the second. Use a hash or counter to mark indices where cumulative sum equals target. The gotcha is that partitions must be contiguous and non-overlapping, and you can't use the last element as a partition point. This is where StealthCoder shines during the OA if you freeze on index boundary logic.

Drill it cold or hedge it with StealthCoder. Either way, don't walk into the OA hoping you remember the trick.

If this hits your live OA

You can drill Three Partition 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. Made for the candidate who got the OA invite this morning and has 72 hours, not six months.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as partition equal subset sum. If you have time before the OA, drill that.

⏵ The honest play

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

Microsoft reuses patterns across OAs. Made for the candidate who got the OA invite this morning and has 72 hours, not six months. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Three Partition Array FAQ

Is this actually dynamic programming or just greedy/prefix sums?+

It's DP-flavored but mostly prefix sums. You build state as you scan the array: 'have I found partition 1 yet, have I found partition 2 yet'. That state machine is the DP. Some solutions use memoization or explicit DP tables, but the fast path is a single scan with counters.

What's the gotcha with boundary indices?+

You can't partition at index 0 or the last index. The three subarrays must all be non-empty. Also, once you identify partition 1 at index i, partition 2 must come strictly after i. Sloppy index logic here causes off-by-one errors that fail edge cases.

How do I prepare for this in 24 hours?+

Drill prefix sums and the two-partition pattern. Microsoft loves state-machine OAs. Sketch out: 'if sum so far equals target and I haven't marked partition 1 yet, mark it'. Then repeat for partition 2. Code it out once cleanly, test on arrays of length 3, 6, and 9.

What's the complexity Microsoft expects?+

O(n) time is the goal. O(n) space is fine if you use a hash or array to track partition positions. If you're doing nested loops, you're slow. Microsoft will test on arrays up to 10^5 elements, so quadratic fails.

Will this pattern show up again in their loop?+

Yes. Microsoft repeats array partitioning and DP state-machine patterns. If you nail Three Partition, you'll recognize K Partition or 'equal subset sum' problems in later rounds. This is a gating pattern.

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

OA at Microsoft?
Invisible during screen share
Get it