Maximize count of subsets having product of smallest element and size of the subset at least X | Java program to implement the above approach ; Function to return the maximum count of subsets possible which satisfy the above condition ; Sort the array in descending order ; Stores the count of subsets ; Stores the size of the current subset ; Check for the necessary conditions ; Driver Code
import java . util . * ; class GFG { static int maxSubset ( Integer arr [ ] , int N , int X ) { Arrays . sort ( arr , Collections . reverseOrder ( ) ) ; int counter = 0 ; int sz = 0 ; for ( int i = 0 ; i < N ; i ++ ) { sz ++ ; if ( arr [ i ] * sz >= X ) { counter ++ ; sz = 0 ; } } return counter ; } public static void main ( String [ ] args ) { Integer arr [ ] = { 7 , 11 , 2 , 9 , 5 } ; int N = arr . length ; int X = 10 ; System . out . print ( maxSubset ( arr , N , X ) ) ; } }