Problem · Array
Split Array Largest Sum
Learn this problemProblem statement
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
splitArray(nums: int[], k: int) → int
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
Example 1
nums = [1, 2, 3, 4, 5]k = 2return = 6The 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
- Minimize Total Input Cost (for LTMS)Seen Jun 2026
- Count Prime StringsONSITE INTERVIEW · Seen Jun 2026
- Final Pod Counts After LogsOA · Seen May 2026
- ATM Queue Exit OrderPHONE SCREEN · Seen May 2026
- Good Ways to Split an ArrayPHONE SCREEN · Seen May 2026
- Generate Seen Binary StringsOA · Seen May 2026
- Update Pod Counts From LogsOA · Seen May 2026
- Minimum Removals to Balance ArrayOA · Seen May 2026