Find pair with maximum difference in any column of a Matrix | Function to find the column with max difference ; Traverse matrix column wise ; Insert elements of column to vector ; calculating difference between maximum and minimum ; Driver Code
function colMaxDiff ( mat ) { let max_diff = Number . MIN_VALUE ; for ( let i = 0 ; i < N ; i ++ ) { let max_val = mat [ 0 ] [ i ] , min_val = mat [ 0 ] [ i ] ; for ( let j = 1 ; j < N ; j ++ ) { max_val = Math . max ( max_val , mat [ j ] [ i ] ) ; min_val = Math . min ( min_val , mat [ j ] [ i ] ) ; } max_diff = Math . max ( max_diff , max_val - min_val ) ; } return max_diff ; } let mat = [ [ 1 , 2 , 3 , 4 , 5 ] , [ 5 , 3 , 5 , 4 , 0 ] , [ 5 , 6 , 7 , 8 , 9 ] , [ 0 , 6 , 3 , 4 , 12 ] , [ 9 , 7 , 12 , 4 , 3 ] ] ; document . write ( " " + colMaxDiff ( mat ) )