Maximum number of elements greater than X after equally distributing subset of array | Function to find the maximum number of elements greater than X by equally distributing ; Sorting the array ; Loop to iterate over the elements of the array ; If no more elements can become larger than x ; Driver Code
function redistribute ( arr , n , x ) { arr . sort ( ) ; arr . reverse ( ) ; let i , sum = 0 ; for ( i = 0 ; i < n ; i ++ ) { sum += arr [ i ] ; if ( ( sum / ( i + 1 ) ) < x ) { document . write ( i ) ; break ; } } if ( i == n ) document . write ( n ) ; } let arr = [ 5 , 1 , 2 , 1 ] ; let x = 3 ; redistribute ( arr , 4 , x ) ;