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
Split Array Largest Sum: Find Optimal Split725108Subarray 1: Sum = 14Subarray 2: Sum = 18Split PointGoal: Minimize the largest subarray sumPossible splits:• [7] | [2,5,10,8] → max(7, 25) = 25• [7,2] | [5,10,8] → max(9, 23) = 23• [7,2,5] | [10,8] → max(14, 18) = 18 ← Optimal• [7,2,5,10] | [8] → max(24, 8) = 24Minimum Largest Sum: 18
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
Asked in
Google 45 Amazon 38 Facebook 32 Microsoft 28
120.0K Views
High Frequency
~25 min Avg. Time
2.7K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen