Find all matrix elements which are minimum in their row and maximum in their column | Functionto find all the matrix elements which are minimum in its row and maximum in its column ; Initialize unordered set ; Traverse the matrix ; Update the minimum element of current row ; Insert the minimum element of the row ; Update the maximum element of current column ; Checking if it is already present in the unordered_set or not ; Driver Code ; Function call ; If no such matrix element is found
function minmaxNumbers ( matrix , res ) { var set = new Set ( ) ; for ( var i = 0 ; i < matrix . length ; i ++ ) { var minr = 1000000000 ; for ( var j = 0 ; j < matrix [ i ] . length ; j ++ ) { minr = Math . min ( minr , matrix [ i ] [ j ] ) ; } set . add ( minr ) ; } for ( var j = 0 ; j < matrix [ 0 ] . length ; j ++ ) { var maxc = - 1000000000 ; for ( var i = 0 ; i < matrix . length ; i ++ ) { maxc = Math . max ( maxc , matrix [ i ] [ j ] ) ; } if ( set . has ( maxc ) ) { res . push ( maxc ) ; } } return res ; } var mat = [ [ 1 , 10 , 4 ] , [ 9 , 3 , 8 ] , [ 15 , 16 , 17 ] ] ; var ans = [ ] ; minmaxNumbers ( mat , ans ) ; if ( ans . length == 0 ) document . write ( " " ) ; for ( var i = 0 ; i < ans . length ; i ++ ) document . write ( ans [ i ] + " " ) ;