Check if a number from every row can be selected such that xor of the numbers is greater than zero | PHP 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
< ? php $ N = 2 ; $ M = 3 ; function check ( $ mat ) { global $ N ; global $ M ; $ xorr = 0 ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { $ xorr = $ xorr ^ $ mat [ $ i ] [ 0 ] ; } if ( $ xorr != 0 ) return true ; for ( $ i = 0 ; $ i < $ N ; $ i ++ ) { for ( $ j = 1 ; $ j < $ M ; $ j ++ ) { if ( $ mat [ $ i ] [ $ j ] != $ mat [ $ i ] [ 0 ] ) return true ; } } return false ; } $ mat = array ( array ( 7 , 7 , 7 ) , array ( 10 , 10 , 7 ) ) ; if ( check ( $ mat ) ) echo " Yes " ; else echo " No " ; ? >