Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80740af

Browse files
authoredSep 19, 2022
Create 1884-egg-drop-with-2-eggs-and-n-floors.js
1 parent b2aa6fa commit 80740af

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed
 
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* @param {number} n
3+
* @return {number}
4+
*/
5+
const twoEggDrop = function (n) {
6+
const dp = Array(n + 1).fill(0)
7+
8+
helper(n)
9+
// console.log(dp)
10+
return dp[n]
11+
12+
function helper(k) {
13+
if(k === 0) return 0
14+
if (dp[k] === 0) {
15+
for (let i = 1; i <= k; i++) {
16+
dp[k] = Math.min(
17+
dp[k] === 0 ? k : dp[k],
18+
1 + Math.max(i - 1, helper(k - i))
19+
)
20+
}
21+
}
22+
return dp[k]
23+
}
24+
}

0 commit comments

Comments
 (0)
Please sign in to comment.