Functional JavaScript 1-liner binary search by value
IntuitionUse binary search up to maximum number of candies per pile, which is 107<224.Time: O(n∗log(m))
Space: O(1)
# Intuition
Use binary search up to maximum number of candies per pile, which is $$10^7 < 2^{24}$$.

``` reduce []
maximumCandies = (candies, k) => [...Array(24).keys()]
    .reduce((s, x) => _.sumBy(candies, y => ~~(y / x), x = s + (1 << 23 - x)) < k ? s : x, 0)
```
``` recursion []
maximumCandies = (candies, k,
    $ = (l, r, m = l + r + 2 >> 1) => r > l
        ? _.sumBy(candies, y => ~~(y / m)) < k
            ? $(l, m - 1)
            : $(m, r)
        : l
) => $(0, ~~(_.sum(candies) / k))
```
``` minified []
// reduce
maximumCandies=(c,k)=>[...Array(25).keys()].reduce((s,x)=>_.sumBy(c,y=>~~(y/x),x=s+(1<<24-x))<k?s:x)
// recursion
maximumCandies=(c,k,$=(l,r,m=l+r+2>>1)=>r>l?_.sumBy(c,y=>~~(y/m))<k?$(l,m-1):$(m,r):l)=>$(0,1e7)
```
Time: $$O(n*log(m))$$
Space: $$O(1)$$
['Array', 'Binary Search', 'JavaScript']