Generate a Matrix such that given Matrix elements are equal to Bitwise OR of all corresponding row and column elements of generated Matrix | Function to find the matrix , A satisfying the given conditions ; Store the final matrix ; Initialize all the elements of the matrix A with 1 ; Traverse the matrix B row - wise ; If B [ i ] [ j ] is equal to 0 ; Mark all the elements of ith row of A as 0 ; Mark all the elements of jth column of A as 0 ; Check if the matrix B can be made using matrix A ; Store the bitwise OR of all elements of A in ith row and jth column ; Traverse through ith row ; Traverse through jth column ; If B [ i ] [ j ] is not equal to c , print " Not ▁ Possible " ; Print the final matrix A ; Driver Code ; Function Call
function findOriginalMatrix ( B , N , M ) { var A = Array ( N ) ; for ( var i = 0 ; i < N ; i ++ ) A [ i ] = Array ( M ) . fill ( 0 ) ; for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { A [ i ] [ j ] = 1 ; } } for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { if ( B [ i ] [ j ] == 0 ) { for ( k = 0 ; k < M ; ++ k ) { A [ i ] [ k ] = 0 ; } for ( k = 0 ; k < N ; ++ k ) { A [ k ] [ j ] = 0 ; } } } } for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { var c = 0 ; for ( k = 0 ; k < M ; ++ k ) { if ( c == 1 ) break ; c += A [ i ] [ k ] ; } for ( k = 0 ; k < N ; ++ k ) { if ( c == 1 ) break ; c += A [ k ] [ j ] ; } if ( c != B [ i ] [ j ] ) { document . write ( " " ) ; return ; } } } for ( i = 0 ; i < N ; ++ i ) { for ( j = 0 ; j < M ; ++ j ) { document . write ( A [ i ] [ j ] + " " ) ; } document . write ( " " ) ; } } var B = [ [ 1 , 1 , 1 ] , [ 1 , 1 , 1 ] ] ; var N = B . length ; var M = B [ 0 ] . length ; findOriginalMatrix ( B , N , M ) ;