Maximize count of subsets into which the given array can be split such that it satisfies the given condition | Java program for the above approach ; Function to count maximum subsets into which the given array can be split such that it satisfies the given condition ; Sort the array in decreasing order ; Stores count of subsets possible ; Stores count of elements in current subset ; Traverse the array arr [ ] ; Update size ; If product of the smallest element present in the current subset and size of current subset is >= K ; Update maxSub ; Update size ; Driver Code ; Given array ; Size of the array ; Given value of X
import java . util . * ; class GFG { static void maxDivisions ( Integer arr [ ] , int N , int X ) { Arrays . sort ( arr , Collections . reverseOrder ( ) ) ; int maxSub = 0 ; int size = 0 ; for ( int i = 0 ; i < N ; i ++ ) { size ++ ; if ( arr [ i ] * size >= X ) { maxSub ++ ; size = 0 ; } } System . out . print ( maxSub + "NEW_LINE"); } public static void main ( String [ ] args ) { Integer arr [ ] = { 1 , 3 , 3 , 7 } ; int N = arr . length ; int X = 3 ; maxDivisions ( arr , N , X ) ; } }