Number of subsets with same AND , OR and XOR values in an Array | Javascript program to find the number of subsets with equal bitwise AND , OR and XOR values ; Function to find the number of subsets with equal bitwise AND , OR and XOR values ; Precompute the modded powers of two for subset counting ; Loop to iterate and find the modded powers of two for subset counting ; Map to store the frequency of each element ; Loop to compute the frequency ; For every element > 0 , the number of subsets formed using this element only is equal to 2 ^ ( frequency [ element ] - 1 ) . And for 0 , we have to find all the subsets , so 2 ^ ( frequency [ element ] ) - 1 ; If element is greater than 0 ; Driver code
var mod = 1000000007 ; function countSubsets ( a , n ) { var answer = 0 ; var powerOfTwo = Array ( 100005 ) . fill ( 0 ) ; powerOfTwo [ 0 ] = 1 ; for ( var i = 1 ; i < 100005 ; i ++ ) powerOfTwo [ i ] = ( powerOfTwo [ i - 1 ] * 2 ) % mod ; var frequency = new Map ( ) ; for ( var i = 0 ; i < n ; i ++ ) if ( frequency . has ( a [ i ] ) ) { frequency . set ( a [ i ] , frequency . get ( a [ i ] ) + 1 ) ; } else { frequency . set ( a [ i ] , 1 ) ; } frequency . forEach ( ( value , key ) => { if ( key != 0 ) answer = ( answer % mod + powerOfTwo [ value - 1 ] ) % mod ; else answer = ( answer % mod + powerOfTwo [ value ] - 1 + mod ) % mod ; } ) ; return answer ; } var N = 6 ; var A = [ 1 , 3 , 2 , 1 , 2 , 1 ] ; document . write ( countSubsets ( A , N ) ) ;