Limited time: AI code review, hints, mock interviews, whiteboard analysis, and all Pro features are unlocked. Enroll

Find the Smallest Divisor Given a Threshold

Medium

Topics
ArrayBinary Search

Given an array nums and an integer target (the threshold), find the smallest positive divisor d such that the sum of ceil(nums[i] / d) over all elements is less than or equal to target. It is guaranteed that a valid divisor exists.

Example 1

Input:  nums = [1,2,5,9], target = 6
Output: 5

Example 2

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

Constraints

  • 1 <= nums.length <= 5*10^4
  • 1 <= nums[i] <= 10^6
  • nums.length <= target <= 10^6
Run ⌘' · Submit ⌘⏎
SensAI SensAI
Beta
Listening...
Tap mic to stop voice mode

Unlock AI Features

One click to activate - no payment, no credit card. Just sign in and you're in.

AI code review and hints
SensAI chat assistant
AI mock interviews
Whiteboard analysis
100% free during early access