Minimum value to be assigned to the elements so that sum becomes greater than initial sum | Function to return the minimum required value ; Find the sum of the array elements ; Return the required value ; Driver code
function findMinValue ( arr , n ) { let sum = 0 ; for ( let i = 0 ; i < n ; i ++ ) sum += arr [ i ] ; return ( parseInt ( sum / n ) + 1 ) ; } let arr = [ 4 , 2 , 1 , 10 , 6 ] ; let n = arr . length ; document . write ( findMinValue ( arr , n ) ) ;