Find the Smallest Divisor Given a Threshold
Given an array of positive integers nums and an integer threshold, choose a positive divisor d. Divide every value by d, round each quotient up independently,…
Given an array of positive integers `nums` and an integer `threshold`, choose a positive divisor `d`. Divide every value by `d`, round each quotient up independently, and add those rounded values. Return the smallest divisor whose rounded-up sum is at most `threshold`.
- `1 <= nums.length <= 5 * 10^4` - `1 <= nums[i] <= 10^6` - `nums.length <= threshold <= 10^6` - Interactive visualization accepts values up to 200 to keep every candidate trace readable.
Example 1: input nums = [1,2,5,9], threshold = 6; output 5. Divisor 5 gives 1 + 1 + 1 + 2 = 5; divisor 4 gives 1 + 1 + 2 + 3 = 7.
Example 2: input nums = [8,4,2,3], threshold = 10; output 2. Divisor 2 gives 4 + 2 + 1 + 2 = 9, while divisor 1 gives 17.
Category: Binary Search. Topic: binary-search. Difficulty: Medium. Patterns: binary-search-on-answer.