![]() |
VOOZH | about |
Given an array of n integers, divide it into k segments and find the maximum of the minimums of k segments. Output the maximum integer that can be obtained among all ways to segment in k subarrays.
Examples:
Input : arr[] = {1, 2, 3, 6, 5}
k = 2
Output: 5
Explanation: There are many ways to create
two segments. The optimal segments are (1, 2, 3)
and (6, 5). Minimum of both segments are 1 and 5,
hence the maximum(1, 5) is 5.
Input: -4 -5 -3 -2 -1 k=1
Output: -5
Explanation: only one segment, so minimum is -5.
There will be 3 cases that need to be considered.
Below is the implementation of the above approach
-5
Time complexity: O(n)
Auxiliary Space: O(1)