Egg drop problem

How to print for every floor ??like I want to print what shall be worst case for floor 1 floor 2 etc out of which we take minimum…

for every floor,try to break every egg from that floor and take the maximum of the two cases-
a)egg breaks
b)egg doesn’t break
How to print this max of each floor so that I can verify my ans for each floor…??
Reply at the earliest…

@S19LPPP0202
you cannot do this, the ans for floor N, and egg K will not be equal to the maximum ans for floor 1,2,N-1 and K eggs.

It will be min of all floors and we will take max /worst case for each floor …by considering both options if egg breaks or not …

Tell me how to print the max/worst value for each floor out of which we are taking min to output as final ans …

Reply at the earliest

eggDrop(n, k) = 1 + min{max(eggDrop(n – 1, x – 1), eggDrop(n, k – x)), where x is in {1, 2, …, k}}
now tell me what do you want to calculate?
eggDrop(n-1,k),eggDrop(n-2,k), …?
because these values will be stored in dp table.

max(eggDrop(n – 1, x – 1), eggDrop(n, k – x)), where x is in {1, 2, …, k}}
I want this one to be printed for every floor…

so just print these values from the dp table.
dp[1][k], dp[2][k], dp[3][k],… dp[n-1][k].

for example if we have 2 eggs and 4 floors and if i print
dp[1][4] it gives 2…
whereas it should be 4 …
why is that so??
my logic::
option 1:if egg breaks at 1 floor then we get our ans .
option 2 :if egg doesnt break then we need to check for remaining floors and that should give total 4 attempts…
so worst case ans for floor 1 should be 4…

Also tell how to print critical floor as well…

Plz reply at the earliest

if dp[1][4] gives 2, then there is some mistake in the implementation. and also you cannot print the critical floor, because you don’t know which is the critical floor. It is not mentioned in the question which is the criticial floor. In fact question is not about finding out critical floor. It is about the minimum tries in the worst case one has to go through if he has to find the critical floor.

Plz provide the code as well

let input be 2eggs 4 floors
in this code the ans for case when we have 2 eggs and we start from 1 floor …is according to you dp[1][2] which is 1 whereeas it should be 4 according to me as we take worst case …

2 egg 1 floor, ans will be 1, and it is eggFloor[2][1]. which is 1 so it is correct.
you can try testcases here https://leetcode.com/problems/super-egg-drop/

https://www.includehelp.com/algorithms/egg-dropping-problem-using-dynamic-programming.aspx

plz look at the example given on this site and its explaination…

input 1:
eggs =2,floors=4

Explanation of the problem:

For the Input 1,

Case 1. Drop at first floor:

  1. Egg does not break:
    If egg does not break then we have three floors left and two eggs. We can either choose 2nd or 3rd floor and proceed similarly but we can easily see we have to do atleast 3 trials.
  2. Egg breaks:
    If egg breaks then we found the critical floor in only 1 trial.

In case 1, the worst possibility is that egg does not break so trials will be 3 for case 1.

Case 2. Drop at second floor:

  1. Egg breaks:
    We are left with one egg and we have to check only 1 floor so number of trials 2.
  2. Egg does not break:
    We still have two eggs and two floors to check we have to check one by one on these floors so trials needed are 3.

So for case 2 together the worst possibility is 3.

In the end we have to find the minimum of case 1, case 2, case 3, case 4.
this explaination shows that for floor 1 trials are 3 …

for floor 1 trials are 3, if you have 2 eggs and 4 floor in total.
If you have only 1 floor and 2 egg then the answer is 1.

Yes I want this to get printed how.to do that??
for floor 1 trials are 3, if you have 2 eggs and 4 floor in total.

Plz reply at the earliest

Why is it 3 in this case(for floor 1 trials are 3, if you have 2 eggs and 4 floor in total.)
I think it should be 4 …because let’s say egg didn’t break at 1 floor and then we went for 2 floor it didn’t break then 3 it didn’t break and then we went 4 floor still didn’t break(egg can. Or can’t break at the top floor given in ques ) …

so in worst case attempts should be 4 but why in the website explanation that I shared and ur code as well it shows 3 attempts??