Skip to content

Commit 02f6470

Browse files
authored
Update 2064-minimized-maximum-of-products-distributed-to-any-store.js
1 parent 741ad74 commit 02f6470

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

2064-minimized-maximum-of-products-distributed-to-any-store.js

+29
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
/**
2+
* @param {number} n
3+
* @param {number[]} quantities
4+
* @return {number}
5+
*/
6+
const minimizedMaximum = function(n, quantities) {
7+
const m = quantities.length
8+
let l = 0, r = Math.max(...quantities)
9+
while(l < r) {
10+
const mid = l + Math.floor((r - l) / 2)
11+
if(valid(mid)) r = mid
12+
else l = mid + 1
13+
}
14+
15+
return l
16+
17+
function valid(mid) {
18+
if(m > n) return false
19+
let res = 0
20+
for (let i = 0; i < m; i++) {
21+
res += Math.ceil(quantities[i] / mid)
22+
}
23+
return res <= n
24+
}
25+
};
26+
27+
// another
28+
29+
130
/**
231
* @param {number} n
332
* @param {number[]} quantities

0 commit comments

Comments
 (0)