hardBinary SearchDynamic ProgrammingBinary Search

Split Array Largest Sum

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

Recognize the pattern

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

Brute force idea

The naive version of Split Array Largest Sum sounds like this: 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.

Better approach

The deeper shift in Split Array Largest Sum is this: 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.

Key invariant

At the center of Split Array Largest Sum is one steady idea: 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.

Watch out for

The trap in Split Array Largest Sum usually looks like this: 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