Largest sub | C # mplementation of the approach ; Function to return the size of the required sub - set ; Sort the array ; HashMap to store the contents of the required sub - set ; Insert the elements satisfying the conditions ; Return the size of the set ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int sizeSubSet ( int [ ] a , int k , int n ) { Array . Sort ( a ) ; Dictionary < int , int > s = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % k != 0 || ! s . ContainsKey ( a [ i ] / k ) ) { if ( s . ContainsKey ( a [ i ] ) ) { var val = s [ a [ i ] ] ; s . Remove ( a [ i ] ) ; s . Add ( a [ i ] , val + 1 ) ; } else { s . Add ( a [ i ] , 1 ) ; } } } return s . Count ; } public static void Main ( String [ ] args ) { int [ ] a = { 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 } ; int n = a . Length ; int k = 2 ; Console . WriteLine ( sizeSubSet ( a , k , n ) ) ; } }