Find the Smallest Divisor Given a Threshold

Given an array of integers nums and an integer threshold, choose a positive integer divisor, divide every element of the array by it, and sum the division results.

Each division result is rounded to the nearest integer greater than or equal to that element. For example, 7 / 3 = 3 and 10 / 2 = 5.

Return the smallest divisor such that the sum of these rounded division results is less than or equal to threshold.

The test cases are generated so that there will be an answer.

Example 1
Inputnums = [1,2,5,9], threshold = 6
Output5
With divisor 1 the sum is 17, with divisor 4 the sum is 7, and with divisor 5 the sum is 5, so 5 is the smallest divisor that satisfies the threshold.
Example 2
Inputnums = [44,22,33,11,1], threshold = 5
Output44
Using divisor 44 makes each rounded division result equal to 1, giving a total sum of 5.

Constraints

  • 1 <= nums.length <= 5 * 10^4
  • 1 <= nums[i] <= 10^6
  • nums.length <= threshold <= 10^6

Asked at 13 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate