Maximize count of subsets having product of smallest element and size of the subset at least X | Comparator function to return the greater of two numbers ; 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
function comp ( a , b ) { return a > b ; } function maxSubset ( arr , N , X ) { arr = arr . sort ( ( a , b ) => b - a ) ; let counter = 0 ; let sz = 0 ; for ( let i = 0 ; i < N ; i ++ ) { sz ++ ; if ( arr [ i ] * sz >= X ) { counter ++ ; sz = 0 ; } } return counter ; } let arr = [ 7 , 11 , 2 , 9 , 5 ] ; let N = arr . length ; let X = 10 ; document . write ( maxSubset ( arr , N , X ) ) ;