You're tasked with optimally partitioning an integer array into exactly k subarrays to minimize the maximum subarray sum.
Given an integer array nums and an integer k, you need to split nums into k non-empty contiguous subarrays such that the largest sum among all subarrays is as small as possible.
Goal: Return the minimized largest sum of the split.
Example: If nums = [7,2,5,10,8] and k = 2, you could split it as [7,2,5] + [10,8] with sums [14, 18]. The largest sum is 18. But if you split as [7] + [2,5,10,8], you get sums [7, 25] with largest sum 25. The optimal split gives the minimum possible largest sum.
Input & Output
Visualization
Time & Space Complexity
Need to check C(n-1,k-1) combinations of split points, each taking O(n) time to calculate sums
Only need space to store current split positions and calculate sums
Constraints
- 1 โค nums.length โค 1000
- 0 โค nums[i] โค 106
- 1 โค k โค min(50, nums.length)
- Each subarray must be non-empty and contiguous