hardBinary SearchDynamic ProgrammingBinary Search

Split Array Largest Sum

hardTime: O(n log(sum))Space: O(1)

Signals to notice

minimize the largest sum among m subarraysbinary search on the answerfeasibility check

Brute force first

Try all ways to split the array into m contiguous subarrays. Exponential in the number of splits. That direct path helps you understand the question, but it tends to treat every possibility as brand new instead of learning from earlier steps.

The key insight

Binary search on the answer (maximum subarray sum). For each candidate, greedily check if the array can be split into ≤ m parts where each part's sum ≤ candidate. Once you hold onto the right piece of information from moment to moment, the problem feels less like trial and error and more like following a shape that was there all along.

What must stay true

If a maximum sum of S allows splitting into ≤ m parts, any S' > S also works. This monotonicity makes binary search valid. Lower bound = max(nums), upper bound = sum(nums). When you keep that truth intact, each local choice supports the larger solution instead of fighting it.

Easy way to go wrong

Lower bound should be max(nums), not 0 — you can't split a single element, so no subarray can have a sum smaller than the largest element. When the code becomes mechanical before the idea is clear, small edge cases start breaking the whole story.

Binary Search Pattern