Divide an array into k segments to maximize maximum of segment minimums | function to calculate the max of all the minimum segments ; if we have to divide it into 1 segment then the min will be the answer ; If k >= 3 , return maximum of all elements . ; Driver Code
< ? php function maxOfSegmentMins ( $ a , $ n , $ k ) { if ( $ k == 1 ) return min ( $ a ) ; if ( $ k == 2 ) return max ( $ a [ 0 ] , $ a [ $ n - 1 ] ) ; return max ( $ a ) ; } $ a = array ( -10 , -9 , -8 , 2 , 7 , -6 , -5 ) ; $ n = count ( $ a ) ; $ k = 2 ; echo maxOfSegmentMins ( $ a , $ n , $ k ) ; ? >