text: Count rows with sum exceeding sum of the remaining Matrix | Javascript program to implement the above approach ; Function to count the number of rows whose sum exceeds the sum of elements of the remaining matrix ; To store the result ; Stores the total sum of the matrix elements ; Calculate the total sum ; Traverse to check for each row ; Stores the sum of elements of the current row ; Calculate the sum of elements of the current row ; If sum of current row exceeds the sum of rest of the matrix ; Increase count ; Print the result ; Given matrix ; Function Call
code: var N = 3 var M = 3 function countRows ( mat ) { var count = 0 ; var totalSum = 0 ; for ( var i = 0 ; i < N ; i ++ ) { for ( var j = 0 ; j < M ; j ++ ) { totalSum += mat [ i ] [ j ] ; } } for ( var i = 0 ; i < N ; i ++ ) { var currSum = 0 ; for ( var j = 0 ; j < M ; j ++ ) { currSum += mat [ i ] [ j ] ; } if ( currSum > totalSum - currSum ) count ++ ; } document . write ( count ) ; } var mat = [ [ 2 , - 1 , 5 ] , [ - 3 , 0 , - 2 ] , [ 5 , 1 , 2 ] ] ; countRows ( mat ) ;