2064. Minimized Maximum of Products Distributed to Any Store
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 63% Topics: Array, Binary Search, Greedy
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(nlogm), m is the max of quantities
# Space: O(1)
class Solution(object):
def minimizedMaximum(self, n, quantities):
"""
:type n: int
:type quantities: List[int]
:rtype: int
"""
def ceil_divide(a, b):
return (a+(b-1))//b
def check(n, quantities, x):
return sum(ceil_divide(q, x) for q in quantities) <= n
left, right = 1, max(quantities)
while left <= right:
mid = left+(right-left)//2
if check(n, quantities, mid):
right = mid-1
else:
left = mid+1
return left
Solution from kamyu104/LeetCode-Solutions · MIT