Leetcode 1408 Solution

This article provides solution to leetcode question 1408 (find-the-smallest-divisor-given-a-threshold)

https://leetcode.com/problems/find-the-smallest-divisor-given-a-threshold

Solution

class Solution:
    def check(self, nums, threshold, val):
        s = 0
        for num in nums:
            s += (num + val - 1) // val
        return s <= threshold

    def smallestDivisor(self, nums: List[int], threshold: int) -> int:
        l = 1
        r = sum(nums)

        while l < r:
            m = (l + r) // 2

            if self.check(nums, threshold, m):
                r = m
            else:
                l = m + 1

        return l