You are given an array of integers nums[] and an integer threshold. You must choose a positive integer divisor and divide each element in the array by it. The result of each division is rounded up to the nearest integer. Return the smallest divisor such that the sum of all the division results is less than or equal to the threshold.
Example 1
Input: nums = [1,2,5,9], threshold = 6
Output: 5
Explanation: If divisor = 5 ceil(1/5) = 1 ceil(2/5) = 1 ceil(5/5) = 1 ceil(9/5) = 2 Sum = 1 + 1 + 1 + 2 = 5 = 6 This is the smallest divisor that satisfies the condition.
Example 2
Input: nums = [44,22,33,11,1], threshold = 5
Output: 44
Explanation: If divisor = 44 ceil(44/44) = 1 ceil(22/44) = 1 ceil(33/44) = 1 ceil(11/44) = 1 ceil(1/44) = 1 Sum = 5 = threshold This is the smallest divisor that satisfies the condition.
Example 3
Input: nums = [2,3,5,7,11], threshold = 11
Output: 3
Explanation: If divisor = 3 ceil(2/3) = 1 ceil(3/3) = 1 ceil(5/3) = 2 ceil(7/3) = 3 ceil(11/3) = 4 Sum = 11 = threshold This is the smallest divisor that satisfies the condition.
Sign in to write, run, and submit your solution against the full test suite.