You’re given an array 'arr' of size 'n' and an integer 'k'.
Your task is to split 'arr' into 'k' sub-arrays such that the maximum sum achieved from the 'k' subarrays formed must be the minimum possible.
A subarray is a contiguous part of the array.
Return the minimum possible value of the maximum sum obtained after splitting the array into 'k' partitions.
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.
3 2
1 1 2
2

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]].
4 3
1 2 3 4
4
.jpeg)
If we want to make three subarrays, there are three possibilities: [[1], [2], [3, 4]], [[1], [2, 3], [4]], and [[1, 2], [3], [4]]. We can see that the maximum sum of any subarray is minimized in the third case. Hence, the answer is 4, which is the maximum sum of any subarray in [[1, 2], [3], [4]].
Check all possible ways of partitioning the given array into ‘k’ subarrays.
In this approach, we will check all the possible ways of partitioning the given array into ‘k’ subarrays.
Algorithm:
O((n - 1) C (k - 1)), where ‘n’ is the number of elements in the array, ‘k’ is the number of sub-arrays such that the maximum sum achieved from the ‘k’ subarrays formed must be the minimum possible and C is the binomial coefficient.
Since there are (n - 1) C (k - 1) ways to divide the given array into ‘k’ subarrays, hence the final time complexity will be O((n - 1) C (k - 1)).
O(n), where ‘n’ is the number of elements in the array.
In the worst case, there can be at most ‘n’ elements in the recursive stack. Hence the final space complexity will be O(n).