Split Array Largest Sum
Problem Statement
You are given an array nums and a number k. Cut the array into exactly k non-empty, contiguous parts. Every number stays in its place; you only choose where to cut.
Each part has a sum. Look at the largest of those k sums. Choose the cuts so that this largest sum is as small as possible, and return it.
An integer array nums and an integer k.
One integer: the smallest possible value of the largest part sum.
Cut into [7, 2, 5] and [10, 8]. The sums are 14 and 18, so the largest is 18. No other cut does better.
Cut into [1, 2, 3] and [4, 5]. The sums are 6 and 9.
- • 1 ≤ nums.length ≤ 1000
- • 0 ≤ nums[i] ≤ 10^6
- • 1 ≤ k ≤ min(50, nums.length)
- • The total sum can reach 10^9, so lo + hi can pass the int limit.
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Try limit max, max+1, … and return the first that needs at most k parts
dp[j][i] = best largest sum for the first i numbers in j parts; try every last cut
Binary search the limit in [max, sum]; check with a greedy part count ≤ k
Turn the question around: for a limit X, can we cut the array so that every part sums to at most X, using at most k parts? Count the parts greedily. Then try X = max, max + 1, max + 2, … and return the first limit that needs at most k parts.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like Binary Search translate into production architectures and low-level memory mechanics.