Count subsequences with same values of Bitwise AND , OR and XOR | function for finding count of possible subsequence ; creating a map to count the frequency of each element ; store frequency of each element ; iterate through the map ; add all possible combination for key equal zero ; add all ( odd number of elements ) possible combination for key other than zero ; driver function
function countSubseq ( arr , n ) { let count = 0 ; let mp = new Map ( ) ; for ( let i = 0 ; i < n ; i ++ ) { mp [ arr [ i ] ] ++ ; if ( mp . has ( arr [ i ] ) ) { mp . set ( arr [ i ] , mp . get ( arr [ i ] ) + 1 ) } else { mp . set ( arr [ i ] , 1 ) } } for ( let i of mp ) { if ( i [ 0 ] == 0 ) count += Math . pow ( 2 , i [ 1 ] ) - 1 ; else count += Math . pow ( 2 , i [ 1 ] - 1 ) ; } return count ; } let arr = [ 2 , 2 , 2 , 5 , 6 ] ; let n = arr . length ; document . write ( countSubseq ( arr , n ) ) ;