Check if a number from every row can be selected such that xor of the numbers is greater than zero | Javascript program to implement the above approach ; Function to check if a number from every row can be selected such that xor of the numbers is greater than zero ; Find the xor of first column for every row ; If Xorr is 0 ; Traverse in the matrix ; Check is atleast 2 distinct elements ; Driver code
let N = 2 ; let M = 3 ; function check ( mat ) { let xorr = 0 ; for ( let i = 0 ; i < N ; i ++ ) { xorr ^= mat [ i ] [ 0 ] ; } if ( xorr != 0 ) return true ; for ( let i = 0 ; i < N ; i ++ ) { for ( let j = 1 ; j < M ; j ++ ) { if ( mat [ i ] [ j ] != mat [ i ] [ 0 ] ) return true ; } } return false ; } let mat = [ [ 7 , 7 , 7 ] , [ 10 , 10 , 7 ] ] ; if ( check ( mat ) ) document . write ( " " ) ; else document . write ( " " ) ;