Count distinct possible Bitwise XOR values of subsets of an array | Javascript 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
let size = 20 ; var dp = new Array ( size ) . fill ( 0 ) ; let ans = 0 ; function insertVector ( mask ) { for ( let i = 0 ; i < 20 ; i ++ ) { if ( ( mask & 1 << i ) == 0 ) continue ; if ( dp [ i ] == 0 ) { dp [ i ] = mask ; ++ ans ; return ; } mask ^= dp [ i ] ; } } function maxSizeSet ( arr , N ) { for ( let i = 0 ; i < N ; i ++ ) { insertVector ( arr [ i ] ) ; } document . write ( 1 << ans ) ; } let arr = [ 1 , 2 , 3 , 4 , 5 ] ; let N = arr . length ; maxSizeSet ( arr , N ) ;