Split Array Largest Sum
1 approach, code in every language
Problem description
You are given an array of non-negative integers and a positive integer k. Cut the array into exactly k contiguous, non-empty pieces without reordering any elements. Every element must belong to exactly one piece.
Among all the ways to make these cuts, look at the piece whose element sum is the largest. Your goal is to arrange the cuts so that this largest piece sum is as small as possible, and return that minimized value.
Example 1
Input: nums = [7, 2, 5, 10, 8], k = 2
Output: 18
The best split is [7, 2, 5] and [10, 8], giving piece sums of 14 and 18. The largest is 18, and no other 2-way split lowers that maximum.
Example 2
Input: nums = [1, 4, 4], k = 3
Output: 4
Each element becomes its own piece: [1], [4], [4]. The largest piece sum is 4, which cannot be reduced with three pieces.
Constraints
1 <= nums.length <= 10^30 <= nums[i] <= 10^61 <= k <= nums.length
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Balanced Truckloads is our own problem on the technique behind Split Array Largest Sum: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.
1,194 problems · 15,062 graded tests · free