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.
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
Examples
01 · Example 1
nums = [1, 2, 3, 4, 5] k = 2 return = 6
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
0 <= k <= 3000 <= n <= 3000 <= nums[i] <= 10^5
More Salesforce problems
- Key Teams in TreeOA · Seen Mar 2026
- System Energy ReductionOA · Seen Mar 2026
- Update Logs by Symmetric XOROA · Seen Mar 2026
- Count Palindromic Concatenation PairsOA · Seen Mar 2026
- Collect Opportunity Data in a TreeOA · Seen Feb 2026
- Replace '?' to Avoid Adjacent DuplicatesOA · Seen Feb 2026
- Strings With No k Consecutive Identical CharactersOA · Seen Feb 2026
- Spam ClassificationSeen Jun 2025
public int splitArray(int[] nums, int k) {
// write your code here
}
nums[1, 2, 3, 4, 5]
k2
expected6
sign in to submit