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.
Example 1
Input: nums = [7,2,5,10,8], k = 2
Output: 18
Explanation: Splitting into [7,2,5] and [10,8] gives sums 14 and 18, so the largest is 18. Every other split has a larger maximum, for example [7,2] and [5,10,8] has 23.
Example 2
Input: nums = [1,2,3,4,5], k = 2
Output: 9
Explanation: Splitting into [1,2,3] and [4,5] gives sums 6 and 9. Moving 4 to the left part would give 10, so 9 is the best.
Example 3
Input: nums = [1,4,4], k = 3
Output: 4
Explanation: With k = 3, each number becomes its own subarray. The largest is 4.
The answer (a maximum subarray sum) lies between max(nums) and sum(nums). For a candidate limit, greedily count how many subarrays are needed; binary search the smallest limit that fits within k.
Run checks all cases above. Submit evaluates all test cases.