Count subsets having distinct even numbers | C # implementation to count subsets having even numbers only and all are distinct ; function to count the required subsets ; inserting even numbers in the set ' us ' single copy of each number is retained ; counting distinct even numbers ; total count of required subsets ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int countSubsets ( int [ ] arr , int n ) { HashSet < int > us = new HashSet < int > ( ) ; int even_count = 0 ; for ( int i = 0 ; i < n ; i ++ ) if ( arr [ i ] % 2 == 0 ) us . Add ( arr [ i ] ) ; even_count = us . Count ; return ( int ) ( Math . Pow ( 2 , even_count ) - 1 ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 4 , 2 , 1 , 9 , 2 , 6 , 5 , 3 } ; int n = arr . Length ; Console . WriteLine ( " Number ▁ of ▁ subsets ▁ = ▁ " + countSubsets ( arr , n ) ) ; } }