Count distinct possible Bitwise XOR values of subsets of an array | Stores the Bitwise XOR of every possible subset ; Function to generate all combinations of subsets and store their Bitwise XOR in set S ; If the end of the subset is reached ; Stores the Bitwise XOR of the current subset ; Iterate comb [ ] to find XOR ; Insert the Bitwise XOR of R elements ; Otherwise , iterate to generate all possible subsets ; Recursive call for next index ; Function to find the size of the set having Bitwise XOR of all the subsets of the given array ; Iterate ove the given array ; Generate all possible subsets ; Print the size of the set ; Driver Code ; Function Call
let s ; function countXOR ( arr , comb , start , end , index , r ) { if ( index == r ) { let new_xor = 0 ; for ( let j = 0 ; j < r ; j ++ ) { new_xor ^= comb [ j ] ; } s . add ( new_xor ) ; return ; } for ( let i = start ; i <= end && end - i + 1 >= r - index ; i ++ ) { comb [ index ] = arr [ i ] ; countXOR ( arr , comb , i + 1 , end , index + 1 , r ) ; } } function maxSizeSet ( arr , N ) { for ( let r = 1 ; r <= N ; r ++ ) { let comb = new Array ( r + 1 ) ; countXOR ( arr , comb , 0 , N - 1 , 0 , r ) ; } document . write ( s . size ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; s = new Set ( ) ; maxSizeSet ( arr , N ) ;