You are given two identical eggs and you have access to a building with n floors labeled from 1 to n.

You know that there exists a floor f where 0 &lt;= f &lt;= n such that any egg dropped at a floor higher than f will break, and any egg dropped at or below floor f will not break.

In each move, you may take an unbroken egg and drop it from any floor x (where 1 &lt;= x &lt;= n). If the egg breaks, you can no longer use it. However, if the egg does not break, you may reuse it in future moves.

Return the minimum number of moves that you need to determine with certainty what the value of f is.

&nbsp;
Example 1:

Input: n = 2
Output: 2
Explanation: We can drop the first egg from floor 1 and the second egg from floor 2.
If the first egg breaks, we know that f = 0.
If the second egg breaks but the first egg didn't, we know that f = 1.
Otherwise, if both eggs survive, we know that f = 2.


Example 2:

Input: n = 100
Output: 14
Explanation: One optimal strategy is:
- Drop the 1st egg at floor 9. If it breaks, we know f is between 0 and 8. Drop the 2nd egg starting from floor 1 and going up one at a time to find f within 8 more drops. Total drops is 1 + 8 = 9.
- If the 1st egg does not break, drop the 1st egg again at floor 22. If it breaks, we know f is between 9 and 21. Drop the 2nd egg starting from floor 10 and going up one at a time to find f within 12 more drops. Total drops is 2 + 12 = 14.
- If the 1st egg does not break again, follow a similar process dropping the 1st egg from floors 34, 45, 55, 64, 72, 79, 85, 90, 94, 97, 99, and 100.
Regardless of the outcome, it takes at most 14 drops to determine f.


&nbsp;
Constraints:


	1 &lt;= n &lt;= 1000


class Solution:
    @cache
    def twoEggDrop(self, n: int) -> int:
        return min((1 + max(i - 1, self.twoEggDrop(n - i)) for i in range (1, n)), default = 1)
class Solution {
    public int twoEggDrop(int n) {
        int egg = 2; // hard coded to 2 eggs for this problem
        int[][] dp = new int[n+1][egg+1];
        return eggDrop(n, egg, dp);
    }

    int eggDrop(int n, int egg, int[][] dp) {
        if(n <= 2 || egg == 1) return n;
        if(dp[n][egg] != 0) return dp[n][egg];
        int min = n; // when you drop at each floor starting from 1
        for(int i = 1; i < n; i++) {
            int eggBreak = 1 + eggDrop(i-1, egg-1, dp); // drops needed if egg breaks at this floor
            int noEggBreak = 1 + eggDrop(n-i, egg, dp); // drops needed if egg does not break at this floor
            int moves = Math.max(eggBreak, noEggBreak); // since we want certain moves for n floor take max
            min = Math.min(min, moves);
        }
        dp[n][egg] = min;
        return min;
    }
}
int dp[1001][1001];
class Solution {
public:
    int solve(int e, int f){
        if(f == 0 || f == 1){
            return f;
        }
        if(e == 1){
            return f;
        }
        if(dp[e][f] != -1) return dp[e][f];
        int mn = INT_MAX;
        int left = 1, right = f;
        while(left <= right){
            int mid = left + (right-left)/2;
            int left_result = solve(e-1,mid-1);
            int right_result = solve(e,f-mid);
            mn = min(mn,1+max(left_result, right_result));
            if(left_result<right_result)
                left = mid+1;
            else
                right = mid-1;
        }
        return dp[e][f] = mn;
    }
    int twoEggDrop(int n) {
        memset(dp, -1, sizeof(dp));
        return solve(2,n);
    }
};
/** https://leetcode.com/problems/egg-drop-with-2-eggs-and-n-floors/
 * @param {number} n
 * @return {number}
 */
var twoEggDrop = function(n) {
  // Writing down strategy on example 2 we can observe following pattern:
  // Drop at floor:   9   22    34    45    55    64    72    79    85    90    94    97    99    100
  // Diff from prev:      13    12    11    10    9     8     7     6     5     4     3     2     1
  
  // So we have hypothesis algorithm
  // That is, `n` minus `d` until `result(n)` is smaller than `d`, where `d` start at 1 and increment by 1 for each iteration. If `result(n)` is 0, subtract 1, else return the result
  
  let d = 1;
  
  while (n > d) {
    n -= d;
    d++;
  }
  
  if (n == 0) {
    d--;
  }
  
  return d;
};
Egg Drop With 2 Eggs and N Floors