Split an Array into k Contiguous Parts to Minimize the Largest Part Sum

Quick Overview

Split an array of non-negative integers into k contiguous, non-empty parts so the largest part sum is as small as possible, and return that sum. The problem tests turning an optimization goal into yes-or-no feasibility checks, proving a greedy check is optimal, and choosing safe search bounds.

Split an Array into k Contiguous Parts to Minimize the Largest Part Sum

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

Given an integer array `nums` and an integer `k`, split `nums` into `k` non-empty subarrays such that the largest sum of any subarray is minimized. Return the minimized largest sum of the split. A subarray is a contiguous part of the array. ### Function Signature ```python def min_largest_split_sum(nums: list[int], k: int) -> int: ``` ### Rules - The `k` subarrays keep the original order and together cover every element exactly once. Each one holds at least one element. - Return only the minimized largest sum, not the split itself. Several splits can reach the same value; the returned number is the same for all of them. ### Constraints - `1 <= len(nums) <= 1000` - `0 <= nums[i] <= 10^6` - `1 <= k <= min(50, len(nums))` ### Examples ```text Input: nums = [7, 2, 5, 10, 8], k = 2 Output: 18 ``` There are four ways to split `nums` into two subarrays. The best is `[7, 2, 5]` and `[10, 8]`, with sums 14 and 18, so the largest sum is 18. ```text Input: nums = [1, 2, 3, 4, 5], k = 2 Output: 9 ``` There are four ways to split `nums` into two subarrays. The best is `[1, 2, 3]` and `[4, 5]`, with sums 6 and 9, so the largest sum is 9. ```text Input: nums = [2, 3, 1, 2, 4, 3], k = 3 Output: 6 ``` The split `[2, 3, 1]`, `[2, 4]`, `[3]` has a largest sum of 6. A largest sum of 5 is impossible: the total is 15, so all three parts would need a sum of exactly 5, and no prefix of the array sums to 10.

Overview: Split an array of non-negative integers into k contiguous, non-empty parts so the largest part sum is as small as possible, and return that sum. The problem tests turning an optimization goal into yes-or-no feasibility checks, proving a greedy check is optimal, and choosing safe search bounds.

Nov 24, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Given an integer array nums and an integer k, split nums into k non-empty subarrays such that the largest sum of any subarray is minimized.

Return the minimized largest sum of the split.

A subarray is a contiguous part of the array.

Function Signature

def min_largest_split_sum(nums: list[int], k: int) -> int:

Rules

  • The k subarrays keep the original order and together cover every element exactly once. Each one holds at least one element.
  • Return only the minimized largest sum, not the split itself. Several splits can reach the same value; the returned number is the same for all of them.

Constraints

  • 1 <= len(nums) <= 1000
  • 0 <= nums[i] <= 10^6
  • 1 <= k <= min(50, len(nums))

Examples

Input: nums = [7, 2, 5, 10, 8], k = 2
Output: 18

There are four ways to split nums into two subarrays. The best is [7, 2, 5] and [10, 8], with sums 14 and 18, so the largest sum is 18.

Input: nums = [1, 2, 3, 4, 5], k = 2
Output: 9

There are four ways to split nums into two subarrays. The best is [1, 2, 3] and [4, 5], with sums 6 and 9, so the largest sum is 9.

Input: nums = [2, 3, 1, 2, 4, 3], k = 3
Output: 6

The split [2, 3, 1], [2, 4], [3] has a largest sum of 6. A largest sum of 5 is impossible: the total is 15, so all three parts would need a sum of exactly 5, and no prefix of the array sums to 10.