Count distinct possible Bitwise XOR values of subsets of an array | Java program for the above approach ; Stores the mask of the vector ; Stores the current size of dp [ ] ; Function to store the mask of given integer ; Iterate over the range [ 0 , 20 ] ; If i - th bit 0 ; If dp [ i ] is zero ; Store the position in dp ; Increment the answer ; Return from the loop ; mask = mask XOR dp [ i ] ; Function to find the size of the set having Bitwise XOR of all the subset of the given array ; Traverse the array ; Print the answer ; Driver code ; Function Call
class GFG { final static int size = 20 ; static int [ ] dp = new int [ size ] ; static int ans ; static void insertVector ( int mask ) { for ( int i = 0 ; i < 20 ; i ++ ) { if ( ( mask & 1 << i ) == 0 ) continue ; if ( dp [ i ] == 0 ) { dp [ i ] = mask ; ++ ans ; return ; } mask ^= dp [ i ] ; } } static void maxSizeSet ( int [ ] arr , int N ) { for ( int i = 0 ; i < N ; i ++ ) { insertVector ( arr [ i ] ) ; } System . out . println ( 1 << ans ) ; } public static void main ( String [ ] args ) { int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ; int N = arr . length ; maxSizeSet ( arr , N ) ; } }