Skip to content

Commit 975b098

Browse files
authored
Create 1739-building-boxes.js
1 parent dc1fac4 commit 975b098

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

1739-building-boxes.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const minimumBoxes = function(n) {
6+
let sum = 1n, base = 1n, row = 1n;
7+
n = BigInt(n)
8+
while (sum < n) {
9+
base += (++row);
10+
sum += base;
11+
}
12+
while (sum > n) {
13+
--base;
14+
sum -= (row--);
15+
if (sum < n) return base + 1n;
16+
}
17+
return base;
18+
};
19+

0 commit comments

Comments
 (0)