Play safe and drop from floor 1 if egg does not break then drop from floor 2 and so on.
Eggs and floors dynamic programming java.
If egg breaks on 27 th floor we try floors form 15 to 26.
Two cases arise 1 if egg breaks we have one egg left so we need three more trials.
Suppose 2 eggs are available.
The optimal number of trials is 14 in worst case.
Given 2 eggs and k floors find the minimum number of trials needed in worst case.
If egg doesn t break on 27 th floor we go to 39 th floor.
N eggs k floors.
Wiki for dynamic programming.
This problem is a specific case of n eggs and k floors.
Try dropping an egg from each floor from 1 to k and calculate the minimum number of dropping needed in worst case.
4 we first try from 4 th floor.
K 10 output.
The problem is not actually to find the critical floor but merely to decide floors from which eggs should be dropped so that total number of trials are minimized.
If egg doesn t break we go to 27th floor.
If egg breaks we one by one try remaining 13 floors.
Base cases eggs 1 floors x.
What is the least number of egg droppings that is guaranteed to work in all cases.
Like other typical dynamic programming dp problems recomputations of same subproblems can be avoided by constructing a temporary array eggfloor in bottom up manner.
So in worst case x times an egg needs to be dropped to find the solution.