Split Array Largest Sum
Problem statement
Given a nonnegative integer array nums and an integer d, split nums into exactly d nonempty contiguous segments.
For a split, calculate the sum of every segment and take the largest segment sum. Return the minimum possible value of that largest sum.
Function
splitArrayLargestSum(nums: int[], d: int) → longExamples
Example 1
nums = [7,2,5,10,8]d = 2return = 18Splitting as [7,2,5] and [10,8] gives segment sums 14 and 18. No two-segment split has a smaller maximum.
Example 2
nums = [1,2,3,4,5]d = 2return = 9The optimal split is [1,2,3] and [4,5], whose largest sum is 9.
Example 3
nums = [1,4,4]d = 3return = 4Exactly three nonempty segments force one element per segment.
Constraints
1 <= nums.length <= 100000.0 <= nums[i] <= 1000000000.1 <= d <= nums.length.- The sum of
numsfits in a signed 64-bit integer.