Uber | Onsite | Split array into k subarrays with min abs diff
Anonymous User
5804

Given an array arr of non-negative integers. You need to split it into k contiguous subarrays such that the absolute difference between max sum and min sum is the smallest and output that difference.

Example:

Input: arr = [3, 4, 5, 3, 7, 2], k = 3
Output: 2
Explanation: Optimal split is subarray1 = [3, 4], subarray2 = [5, 3], subarray3 = [7, 2]
Min sum = 7 and max sum = 9, hence the answer is |7 - 9| = 2.
Comments (9)