O81

Find the Smallest Divisor Given a Threshold

Mid / Senior Engineer
Target Time: 25 - 35 Minutes
Type: NUMERIC

Problem Statement & Objective

Given an array of integers nums and an integer threshold, we will choose a positive integer divisor and divide all the array by it and sum the result's ceiling. Find the smallest divisor such that the sum <= threshold.

Function Signature (Python)

smallest_divisor(nums: list[int], threshold: int) -> int

Input & Output Contract

Output Rule:En küçük bölen pozitif tam sayısı.

System Constraints

1 <= sayilar.length <= 5 * 10^4
1 <= sayilar[i] <= 10^6
sayilar.length <= esik <= 10^6

Example Execution Walkthrough

sayilar = [1, 2, 5, 9], esik = 6 -> bolen = 5 için:
ceil(1/5)+ceil(2/5)+ceil(5/5)+ceil(9/5) = 1 + 1 + 1 + 2 = 5 <= 6 -> cevap: 5

Example Test Scenarios (3)

Example 1
Input:[[1,2,5,9],6]
Expected Output:5
Example 2: esik = n
Input:[[44,22,33,11,1],5]
Expected Output:44
Example 3: Geniş Eşik
Input:[[21212,10101,12121],1000000]
Expected Output:1
Loading Python Editor...
Input Parameters
[
  [
    1,
    2,
    5,
    9
  ],
  6
]
Expected Output
5