Split Array Largest Sum
Master this topic with zero to advance depth.
Split Array Largest Sum
Given an integer array nums and an integer k, split the array into k non-empty contiguous subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split.
Examples
Level I: Dynamic Programming
Intuition
Try all possible ways to split the array using recursion with memoization. dp[i][j] represents the minimum largest sum for the subarray nums[i:] split into j parts.
Detailed Dry Run
nums = [7,2,5], k=2
- Split at index 1: max(7, 2+5=7) = 7
- Split at index 2: max(7+2=9, 5) = 9 Min results: 7.
Level III: Optimal (Binary Search on Answer)
Intuition
The minimum largest sum ranges from max(nums) to sum(nums). This range is monotonic: if a max-sum is feasible with splits, is also feasible. We binary search for the smallest .
Detailed Dry Run
| Step | L | R | Mid | Count | Decision |
|---|---|---|---|---|---|
| 1 | 10 | 32 | 21 | 2 | R = 21 |
| 2 | 10 | 21 | 15 | 3 | L = 16 |
| 3 | 16 | 21 | 18 | 2 | R = 18 |
| Exit | - | - | - | - | Return 18 |
Found an issue or have a suggestion?
Help us improve! Report bugs or suggest new features on our Telegram group.