Problem Brief
Split Array Largest Sum
FULLTIMEOA
See Salesforce online assessment and hiring insights
Given an integer array nums of size n and an integer k,
split nums into k non-empty contiguous subarrays such that the sum of
maximum values of each subarray is minimized.
Function Description
Complete the function splitArray in the editor.
splitArray has the following parameters:
- 1.
int[] nums: an integer array - 2.
int k: the number of subarrays to split into
Returns
int: the minimum sum of the maximum values of the k subarrays
1Example 1
Input
nums = [1, 2, 3, 4, 5], k = 2
Output
6
Explanation
The optimal split is [1], [2, 3, 4, 5]. The sum of the maximum values of each subarray is max([1]) + max([2, 3, 4, 5]) = 1 + 5 = 6.
Constraints
Limits and guarantees your solution can rely on.
0 <= k <= 3000 <= n <= 3000 <= nums[i] <= 10^5