


Input: ‘arr’ = [1, 1, 2] and ‘k’ = 2
Output: 2
Explanation: If we want to make two subarrays, there are two possibilities: [[1], [1, 2]] and [[1, 1], [2]]. We can see that the maximum sum of any subarray is minimized in the second case. Hence, the answer is 2, which is the maximum sum of any subarray in [[1, 1], [2]].
The first line contains two integers denoting 'n' and 'k', representing the number of array elements and the number of sub-arrays we need to split the array into.
The second line contains 'n' space-separated integers denoting the elements of the array.
Return the minimum possible value of the maximum sum obtained after splitting the array into 'k' partitions.
You do not need to print anything; it has already been taken care of. Just implement the given function and return the sum.
1 <= 'n' <= 10^4
1 <= 'k' <= N
1 <= 'arr[i]' <= 10^4
Time limit: 1 sec
The expected time complexity is O(n * log(sum)), where 'n' is the number of elements in the array and 'sum' is the sum of elements of the array.
In this approach, we will check all the possible ways of partitioning the given array into ‘k’ subarrays.
If we get one valid value of sum, where the valid value of sum is that sum value which will not be exceeded by any of the ‘k’ subarray sums then, all other values that are greater than it will be valid as well, but we want only the minimum valid sum. Hence, an efficient way to find the minimum sum is to use a binary search.