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
s = set ( [ ] ) NEW_LINE def countXOR ( arr , comb , start , end , index , r ) : NEW_LINE INDENT if ( index == r ) : NEW_LINE INDENT new_xor = 0 NEW_LINE for j in range ( r ) : NEW_LINE INDENT new_xor ^= comb [ j ] NEW_LINE DEDENT s . add ( new_xor ) NEW_LINE return NEW_LINE DEDENT i = start NEW_LINE while i <= end and ( end - i + 1 ) >= ( r - index ) : NEW_LINE INDENT comb [ index ] = arr [ i ] NEW_LINE countXOR ( arr , comb , i + 1 , end , index + 1 , r ) NEW_LINE i += 1 NEW_LINE DEDENT DEDENT def maxSizeSet ( arr , N ) : NEW_LINE INDENT for r in range ( 2 , N + 1 ) : NEW_LINE INDENT comb = [ 0 ] * ( r + 1 ) NEW_LINE countXOR ( arr , comb , 0 , N - 1 , 0 , r ) NEW_LINE DEDENT print ( len ( s ) ) NEW_LINE DEDENT arr = [ 1 , 2 , 3 , 4 , 5 ] NEW_LINE N = len ( arr ) NEW_LINE maxSizeSet ( arr , N ) NEW_LINE