Smallest Divisor Given Threshold
mediumTime: O(n log max)Space: O(1)
Recognize the pattern
smallest divisor keeping sum ≤ thresholdbinary search on divisorceiling division
Brute force idea
Try every divisor from 1 to max(nums) — O(max × n).
Better approach
Binary search on divisor in [1, max(nums)]. For each candidate, compute sum of ceil(nums[i]/divisor). If sum ≤ threshold, divisor works (try smaller). O(n log max).
Key invariant
Larger divisor → smaller sum (monotonic). Binary search finds the smallest divisor where sum ≤ threshold.
Watch out for
Using floor division instead of ceiling — each element contributes ceil(num/d), not floor.