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
int countSubseq ( int arr [ ] , int n ) { int count = 0 ; unordered_map < int , int > mp ; for ( int i = 0 ; i < n ; i ++ ) mp [ arr [ i ] ] ++ ; for ( auto i : mp ) { if ( i . first == 0 ) count += pow ( 2 , i . second ) - 1 ; else count += pow ( 2 , i . second - 1 ) ; } return count ; } int main ( ) { int arr [ ] = { 2 , 2 , 2 , 5 , 6 } ; int n = sizeof ( arr ) / sizeof ( arr [ 0 ] ) ; cout << countSubseq ( arr , n ) ; return 0 ; }