Find the Smallest Divisor Given a Threshold

Med
Concept
Code
Loading editor...
Tap Analyze to see visualization
Variables

Run code to see variables

Output

Console output will appear here

Press Space to start to step? all shortcuts

Solution Guide: Find the Smallest Divisor Given a Threshold

Approach

For each candidate divisor, compute required sum of hours (ceil division). If the sum fits threshold, search smaller divisors; otherwise search larger.

Complexity Analysis

Time
O(n log m) where m is max(nums)
Space
O(1)

Pattern

Binary Search on Answer

Why It Works

If a divisor d is valid (sum <= threshold), every larger divisor is also valid. Monotonic feasibility allows binary search for the minimum valid d.

Updated Feb 2026