
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
There exists a monotonic nature such that when x is smaller than some number, there will be no way to distribute, and when x is not smaller than that number, there will always be a way to distribute.
If you are given a number k, where the number of products given to any store does not exceed k, could you determine if all products can be distributed?
Implement a function canDistribute(k), which returns true if you can distribute all products such that any store will not be given more than k products, and returns false if you cannot. Use this function to binary search for the smallest possible k.