Given an array of non-negative integers nums and an integer k, split the array into k non-empty contiguous subarrays. Return the minimum possible value of the largest sum among these subarrays.
Example 1
Input: nums = [7,2,5,10,8], k = 2
Output: 18
Explanation: The best split is [7,2,5] and [10,8]. The largest sum among the subarrays is 18, which is minimized.
Example 2
Input: nums = [1,2,3,4,5], k = 2
Output: 9
Explanation: The best split is [1,2,3] and [4,5]. The largest sum is 9, which is the minimum possible.
Example 3
Input: nums = [1,4,4], k = 3
Output: 4
Explanation: Each element is its own subarray: [1], [4], [4]. The largest sum is 4.
Approach, complexity and clean code in every language. Sign in to unlock the editorial.
Your submissions, results and runtime history live here. Sign in to start your streak.
7 2 5 10 8 2
18
7 2 5 10 8 3
14
1 2 3 4 5 2
9