Комментарии:
Nice solution but not easy for beginner to understand easily
ОтветитьNice Explanation
Ответитьactually this is first time i've seen someone posted a detailed solution for this problem instead just a stupid math equation without any explanation. good work. i m officially a fan
Ответитьwhy did we calculate min and max?? Reason??
ОтветитьTushar Roy is God of algorithms... He explains in a way no one else does
ОтветитьWhy are we adding 1+ with max..
ОтветитьYou explained the solution so well, it truly helped me understand the solution.
ОтветитьMISTAKE (always droop from the middle if you have more than one egg):
There is a fundamental logical MISTAKE and while it does not affect the result, it does simplify the solution when realized. See:
If you have more than one egg, you can start drooping the first egg from any of the N floors. So, you evaluate the cost of dropping from each floor and stay with the floor that yields the minimum cost (min).
But when you think better, that is completely unnecessary: you don't need to evaluate all the floors, because the middle floor will always yield the minimum drooping cost. Always!
Now, depending on N (even or odd), the middle floor might or might not have an equal number of floors above and below. When it does not, you stay with the worst case scenery: solve the problem with more floors (max).
Applying this logic, you eliminate the min operation that evaluates all possible floors (go always with the middle) and the solution to the problem cuts down as follows:
def eggs(N,e):
if e==1:
return N
if N==1:
return 1
mid=math.ceil(N/2)
if (N-mid)>(mid-1):
return eggs(N-mid,e)+1
else:
return eggs(mid-1,e-1)+1
Explanation of the middle selection: Suppose you have 100 floors and just 2 eggs. You droop the first egg from 99: in the best case it does not break and with the remaining egg you scan the only floor left, the floor 100 (the one above you). So the best case is 2 droops! But in the worst case (it did not break), you have to scan 98 floors below you one by one with the only remaining egg. This makes 98 droops for the worst case. Thus, you are risking a lot (too much difference between the best and the worst case, and you don’t know what the case will be). So:
99: 2 (best)-98(worst)
98: 3(best)-97(worst)
97: 4(best)-96(worst)
.
.
4: 4(best)-96(worst)
3: 3(best)-97(worst)
2: 2 (best)-98(worst)
Look! When you go downwards the risk reduces (the difference between best and worst case tends to zero) but, it happens like that also when you go upwards. So, in the middle point the risk will be near zero (depending of N being even or odd). But, in any case, the middle point (as Buddha said) will always be the most neutral or best option to droop any time you have more than one egg (the one with minimum cost).
guy looks like a mad scientist
ОтветитьThe first video which explains the problem with a logical explanation instead of moving to equation.Thanks a lot, Tushar for making video and putting ur effort on it.
ОтветитьThis was a good explanation of this problem. I really liked it and learned a lot. Thank you. Some problem statements ask for the maximum number of floors which can be covered at each step. That is the inverse of the minim attempts I guess. So in case of six floors/2eggs, the maximum floors at each step is 2. Right?
ОтветитьI just wanna know what kind of this sturdy egg is
ОтветитьGreat explanation
ОтветитьThe real question is, does the egg stay the same after surviving repeated drops? Hard to say....
ОтветитьYour video is great but TLE happened using your code.
ОтветитьSimply awesome!!
Ответитьwhy we are adding 1 in max()
ОтветитьInstructions unclear, I broke all the eggs.
ОтветитьWell explained.
ОтветитьThis isn't a practical solution
ОтветитьSir, we can even find out using binary search, so if n is number of eggs, and f is number of floors, time complexity will be O(nlog(f)) and space complexity will be O(1).
ОтветитьBro I have a doubt.. that Whether all the eggs to be dropped from the same floor?
ОтветитьSuper awesome
Ответитьyou dont need to be a foreigner being indian, try to spell and pronounce properly rather than talking in foreign style....
ОтветитьFuck carryminati, mi and my bois watch Tushar Roy - Coding Made Simple.
ОтветитьI am from NIT jalandhar and You>????
ОтветитьTushar #1
ОтветитьAny improved version cause I'm getting TLE...
ОтветитьI am getting a TLE with this logic :(
ОтветитьEast or west Tushar is the best!! Thank you
Ответитьyou are a great teacher you have helped me a lot, i am very much thankful to you.
ОтветитьNice Explanation for egg breaking
ОтветитьTushar,
There is a flaw in your video in the sense that the explanation you gave is for dynamic programming using a nxk matrix while your formula is based on recursion.
In the explanation you had used the following formula -
f[n][k] = min(1 + max( f[n-1][j-1] , f[n][j-x] ) where x ranges from 1 to j )
Here n = number of eggs and k = number of floors
Thanks for taking the time to break it down and explain it step by step!
ОтветитьGuy he is wrong;
I tried it today it broke on first floor itself so only one egg is needed😐
this man is too good.
Ответитьtime complexity is O(n^3)
ОтветитьCan you please tell me how you decide if egg breaks or not. everyone is talking about egg breaks but the question is what condition we should put while coding to know if the egg breaks or not?
ОтветитьNice explanation and very much greatful to you, best video of this question
ОтветитьThank you very much!
ОтветитьTushar Roy 5years later still the best solution to the problem. YOU ROCK!!!
ОтветитьHow to solve it with O(n*k) TC?
ОтветитьI didnt under why did he use max in equation. If someone understood please explain.
ОтветитьAwesome.
Ответитьgreat work but your solution doesn't pass all test cases in leetcode just fyi
ОтветитьCopilot take me to this vedio 🤔
Ответить