Split Array Largest Sum - Problem
Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.
Return the minimized largest sum of the split.
A subarray is a contiguous part of the array.
Input & Output
Example 1 — Basic Split
$
Input:
nums = [7,2,5,10,8], k = 2
›
Output:
18
💡 Note:
Split into [7,2,5] and [10,8]. The sums are 14 and 18, so the largest sum is 18, which is minimal among all possible splits.
Example 2 — Multiple Small Subarrays
$
Input:
nums = [1,2,3,4,5], k = 2
›
Output:
9
💡 Note:
Split into [1,2,3,4] and [5]. The sums are 10 and 5, giving largest sum 10. Better split: [1,2,3] and [4,5] gives sums 6 and 9, so answer is 9.
Example 3 — Edge Case k=1
$
Input:
nums = [1,4,4], k = 1
›
Output:
9
💡 Note:
Cannot split array when k=1, so return sum of entire array: 1+4+4=9.
Constraints
- 1 ≤ nums.length ≤ 1000
- 1 ≤ k ≤ min(50, nums.length)
- 0 ≤ nums[i] ≤ 106
Visualization
Tap to expand
Understanding the Visualization
1
Input
Array [7,2,5,10,8] with k=2 splits needed
2
Process
Find split positions that minimize largest subarray sum
3
Output
Minimum largest sum = 18
Key Takeaway
🎯 Key Insight: Binary search on the answer range combined with greedy validation gives optimal O(n log sum) solution
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code