Find the Smallest Divisor Given a Threshold LeetCode solution in JavaScript

1
var smallestDivisor = function (nums, threshold) {
2
let left = 1;
3
let right = nums.reduce((r, x) => Math.max(r, x), 0);
4

5
while (left <= right) {
6
const div = Math.floor((left + right) / 2);
7
const sum = nums.reduce((r, x) => r + Math.ceil(x / div), 0);
8

9
if (sum <= threshold) {
10
right = div - 1;
11
} else {
12
left = div + 1;
13
}
14
}
15

16
return left;
17
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0