Ways to split array into two groups of same XOR value | Return the count number of ways to split array into two groups such that each grouphas equal XOR value . ; We can split only if XOR is 0. Since XOR of all is 0 , we can consider all subsets as one group . ; Driver Code
< ? php function countgroup ( $ a , $ n ) { $ xs = 0 ; for ( $ i = 0 ; $ i < $ n ; $ i ++ ) $ xs = $ xs ^ $ a [ $ i ] ; if ( $ xs == 0 ) return ( 1 << ( $ n - 1 ) ) - 1 ; return 0 ; } $ a = array ( 1 , 2 , 3 ) ; $ n = count ( $ a ) ; echo countgroup ( $ a , $ n ) ; ? >