531. Split Array Largest Sum (Optimal)

HardBinary SearchBinary Search on AnswerDP

Given an array and an integer k, split it into k non-empty contiguous subarrays so that the largest subarray sum is minimized, and return that minimized largest sum. This is the optimal O(n log(sum)) binary-search-on-answer formulation. Input: '[arr], k'.

Input: '[arr], k'.

Output: Integer — the minimized largest subarray sum.

Examples

Example 1
Input: [7,2,5,10,8], 2
Output: 18
Explanation: Split [7,2,5] and [10,8].
Example 2
Input: [1,2,3,4,5], 2
Output: 9
Explanation: [1,2,3] and [4,5].
Example 3
Input: [1], 1
Output: 1
Explanation: Single subarray.

Constraints

Asked by

GoogleAmazonInfosysBloombergDeloitteMicrosoft
Solve this problem in the editor →