gary@interview:~/interview/coding/1283-find-the-sm….md$
$ cat ./coding/1283-find-the-smallest-divisor-given-a-threshold.md
[Coding]

1283. Find the Smallest Divisor Given a Threshold

────────────────────────────────────────────────────────────

1283. Find the Smallest Divisor Given a Threshold

這題只要先做過 875. Koko Eating Bananas 就會了。

class Solution:
    def smallestDivisor(self, nums: List[int], threshold: int) -> int:
        
        def findDivisor(divisor):
            res = 0
            for num in nums:
                res += num//divisor
                if num % divisor != 0:
                    res += 1
            return res
        
        left = 1
        right = max(nums)
        
        while left <= right:
            mid = left + (right - left)//2
            divisor = findDivisor(mid)
            if divisor <= threshold: # divisor is too large
                right = mid - 1
            else:
                left = mid + 1
        
        
        return left
--tags#Binary Search
$ ls ./coding/ | grep -v 1283-find-the-smallest-divisor-given-a-threshold
265. Paint House II256. Paint House143. Reorder List1762. Buildings With an Ocean View
← cd ../codingcd ~