Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Split Array Largest Sum

Medium Acceptance 59.00% Points 30.00

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.

Examples
Example 1

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

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

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.

Hints
Hint 1
N/A
Constraints
  • 1 = nums.length = 105
  • 0 = nums[i] = 105
  • 1 = k = nums.length
Companies
Apple
Topics
Binary Search
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions