Skip to content
Decoder

Find the Smallest Divisor Given a Threshold

Medium

Problem

Given a list of positive integers nums and an integer threshold, choose a positive integer divisor d. Divide every number by d, rounding each result up, and add the results. Return the smallest divisor whose total is <= threshold.

Example 1

Input
nums = [1, 2, 5, 9], threshold = 6
Output
5
Why
1 + 1 + 1 + 2 = 5

Example 2

Input
nums = [44, 22, 33, 11, 1], threshold = 5
Output
44

Example 3

Input
nums = [2, 3, 5, 7, 11], threshold = 11
Output
3

Constraints

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

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.