Minimize the maximum element in constructed Array with sum divisible by K | Function to find smallest maximum number in an array whose sum is divisible by K . ; Minimum possible sum possible for an array of size N such that its sum is divisible by K ; If sum is not divisible by N ; If sum is divisible by N ; Driver code .
function smallestMaximum ( N , K ) { let sum = Math . floor ( ( N + K - 1 ) / K ) * K ; if ( sum % N != 0 ) return Math . floor ( sum / N ) + 1 ; else return Math . floor ( sum / N ) ; } let N = 4 ; let K = 3 ; document . write ( smallestMaximum ( N , K ) ) ;