1283. Find the Smallest Divisor Given a Threshold
Read the full problem statement on LeetCode.
Difficulty: medium Acceptance: 63% Topics: Array, Binary Search
View full problem on LeetCode Reading material
Reference solution (spoiler · python)
# Time: O(logn)
# Space: O(1)
class Solution(object):
def smallestDivisor(self, nums, threshold):
"""
:type nums: List[int]
:type threshold: int
:rtype: int
"""
def check(A, d, threshold):
return sum((i-1)//d+1 for i in nums) <= threshold
left, right = 1, max(nums)
while left <= right:
mid = left + (right-left)//2
if check(nums, mid, threshold):
right = mid-1
else:
left = mid+1
return left
Solution from kamyu104/LeetCode-Solutions · MIT
Similar questions