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
static int countSubseq ( int [ ] arr , int n ) { int count = 0 ; Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { var val = mp [ arr [ i ] ] ; mp . Remove ( arr [ i ] ) ; mp . Add ( arr [ i ] , val + 1 ) ; } else { mp . Add ( arr [ i ] , 1 ) ; } } foreach ( KeyValuePair < int , int > entry in mp ) { if ( entry . Key == 0 ) count += ( int ) ( Math . Pow ( 2 , entry . Value - 1 ) ) ; else count += ( int ) ( Math . Pow ( 2 , entry . Value - 1 ) ) ; } return count ; } public static void Main ( String [ ] args ) { int [ ] arr = { 2 , 2 , 2 , 5 , 6 } ; int n = arr . Length ; Console . WriteLine ( countSubseq ( arr , n ) ) ; } }