Count positions in Binary Matrix having equal count of set bits in corresponding row and column | Function to return the count of indices in from the given binary matrix having equal count of set bits in its row and column ; Stores count of set bits in corresponding column and row ; Traverse matrix ; Since 1 contains a set bit ; Update count of set bits for current row and col ; Stores the count of required indices ; Traverse matrix ; If current row and column has equal count of set bits ; Return count of required position ; Driver Code
function countPosition ( mat ) { var n = mat . length ; var m = mat [ 0 ] . length ; var row = Array . from ( { length : n } , ( _ , i ) => 0 ) ; var col = Array . from ( { length : m } , ( _ , i ) => 0 ) ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( mat [ i ] [ j ] == 1 ) { col [ j ] ++ ; row [ i ] ++ ; } } } var count = 0 ; for ( i = 0 ; i < n ; i ++ ) { for ( j = 0 ; j < m ; j ++ ) { if ( row [ i ] == col [ j ] ) { count ++ ; } } } return count ; } var mat = [ [ 0 , 1 ] , [ 1 , 1 ] ] ; document . write ( countPosition ( mat ) ) ;