Skip to content

visual walkthrough

Split Array Largest Sum

HardBinary Search on AnswerReported at: GoogleAmazonMeta+2

Minimise the maximum subarray sum; a classic Hard.

Solve on LeetCode

The idea

Turn "minimise the biggest part" into a yes/no: can the array be cut into at most k parts, each summing to ≤ limit?

A bigger limit never needs more parts, so binary search the smallest limit that says yes. Checking a limit is greedy: fill a part until the next number won't fit.

Complexity

approachtimespace
Try every splitO(C(n, k))O(k)
Binary search the limitO(n log sum)O(1)

More walkthroughs