#410

Split Array Largest Sum

Hard Binary search on the answer (book allocation)

  1. Read
  2. Understand
  3. Hints
  4. Approach
  5. Solution
  6. Solved

?The problem

Split the array into k non-empty contiguous parts so that the largest part's sum is as small as possible. Return that sum.

This is a short summary in our own words. Read the full statement and examples on LeetCode: open problem ↗

◎Understanding

Really asking: cut the array into k parts so the biggest part sum is as small as possible ("book allocation").

Why this works: guess a limit; greedily count how many parts you need. Fewer parts than k is fine. Binary search the smallest workable limit.

Example: [7, 2, 5, 10, 8], k = 2

limit 18: [7,2,5] [10,8] → 2 parts ✓limit 17: [7,2,5] [10] [8] → 3 parts ✗ → answer 18

✦Hints open one at a time

↗Approach

</>Solution (Java)

!Common mistake

Thinking "at most k parts" is a problem — if fewer parts fit, you can always split further without increasing the max.

Solve on LeetCode ↗
Complexity
  • Time: O(n log(sum)).
  • Space: O(1).
Topic: Binary Search
🎬 Episodes 21–23: video coming soon