Maximize minimum of array generated by maximums of same indexed elements of two rows of a given Matrix | Function to find the maximum of minimum of array constructed from any two rows of the given matrix ; Initialize global max as let_MIN ; Iterate through the rows ; Iterate through remaining rows ; Initialize row_min as let_MAX ; Iterate through the column values of two rows ; Find max of two elements ; Update the row_min ; Update the global_max ; Prlet the global max ; Given matrix mat [ ] [ ] ; Given number of rows and columns ; Function Call
function getMaximum ( N , M , mat ) { let global_max = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = i + 1 ; j < N ; j ++ ) { let row_min = Number . MAX_VALUE ; for ( let k = 0 ; k < M ; k ++ ) { let m = Math . max ( mat [ i ] [ k ] , mat [ j ] [ k ] ) ; row_min = Math . min ( row_min , m ) ; } global_max = Math . max ( global_max , row_min ) ; } } return global_max ; } let mat = [ [ 5 , 0 , 3 , 1 , 2 ] , [ 1 , 8 , 9 , 1 , 3 ] , [ 1 , 2 , 3 , 4 , 5 ] , [ 9 , 1 , 0 , 3 , 7 ] , [ 2 , 3 , 0 , 6 , 3 ] , [ 6 , 4 , 1 , 7 , 0 ] ] ; let N = 6 , M = 5 ; document . write ( getMaximum ( N , M , mat ) ) ;