Largest sub | Java implementation 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
import java . util . * ; class GFG { static int sizeSubSet ( int a [ ] , int k , int n ) { Arrays . sort ( a ) ; HashMap < Integer , Integer > s = new HashMap < Integer , Integer > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( a [ i ] % k != 0 || s . get ( a [ i ] / k ) == null ) s . put ( a [ i ] , s . get ( a [ i ] ) == null ? 1 : s . get ( a [ i ] ) + 1 ) ; } return s . size ( ) ; } 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 ; System . out . println ( sizeSubSet ( a , k , n ) ) ; } }