43 Egg Dropping Problem Recursive

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ส.ค. 2024
  • Egg Dropping using Recursion
    Problem statement: You are given N floor and K eggs. You have to minimize the number of times you have to drop the eggs to find the critical floor where critical floor means the floor beyond which eggs start to break. Assumptions of the problem:
    If egg breaks at ith floor then it also breaks at all greater floors.
    If egg does not break at ith floor then it does not break at all lower floors.
    Unbroken egg can be used again.
    Note: You have to find minimum trials required to find the critical floor not the critical floor.
    Example:
    Input:
    4
    2
    Output:
    Number of trials when number of eggs is 2 and number of floors is 4: 3
    PROBLEM STATEMENT LINK:www.includehel....
    Playlist Link: • Dynamic Programming | ... .
    ------------------------------------------------------------------------------------------
    Here are some of the gears that I use almost everyday:
    🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
    👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
    💻 : My gaming laptop: amzn.to/3yjcn23
    📱 : My Ipad: amzn.to/39yEMGS
    ✏️ : My Apple Pencil: amzn.to/3kMnKYf
    🎧 : My Headphones: amzn.to/3kMOzM7
    💺 : My Chair: amzn.to/385weqR
    🛋 : My Table: amzn.to/3kMohtd
    ⏰ : My Clock: amzn.to/3slFUV3
    🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
    PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

ความคิดเห็น • 278

  • @prabhatpandey1638
    @prabhatpandey1638 4 ปีที่แล้ว +436

    It is very important to understand why we are sending (f-k) in case of egg didn't break and again
    using a for loop where k is initiated from 1 again.
    the reason is we are checking for a range where we are min number of possibly attempt where egg didn't break.
    Let's say in simple terms there are 10 floor.
    Egg didn't break from 7th floor. So now only 10-7 = 3 floor needs to be checked.
    But to check the next 3 floor we need to use a k loop again.
    Here k=1 will represent 8th floor.
    Here k=2 will represent 9th floor.
    Here k=3 will represent 10th floor.
    So to answer the initial question , You need to check the min number of attempts in next 3 floors and that is why you are sending (f-k) and k range is (1,f-k)
    PS. I was not able to understand for 2 days why we are looping from K=1 again. Putting this explanation out incase someone gets stuck in the same point again.

    • @nileshdand2431
      @nileshdand2431 3 ปีที่แล้ว +6

      Bro can u explain why are we using max, i.e how are we understanding the worst the case in this

    • @monildand4366
      @monildand4366 3 ปีที่แล้ว +2

      can you explain use of max.

    • @kumarsaurabhraj6917
      @kumarsaurabhraj6917 3 ปีที่แล้ว +57

      @@nileshdand2431 Will try to explain this, we have to find the minimum number of attempt to find the critical floor, we don't know which floor would be the most optimal floor to make the first attempt hence we are trying out all the floors through the loop, also we do not know if dropping from a certain floor will cause the egg to break or not so we are testing for both cases one in which we assume that the egg would break and in the other we assume that it won't, recursive calls with left over eggs and floors in both cases give us the number of attempts required. But since the question asks us to assume the worst case we take the possibility as a fact which requires greater number of attempts to find the critical floor.
      In simpler terms, suppose if we are testing for the 3rd floor then we check the number of attempts to find the critical floor for both cases if the egg would break from the 3rd floor and if the egg wont break from the 3rd floor, if it requires greater number of attempts to find the critical floor if the egg would break if dropped form the 3rd floor then we would assume that upon dropping from the 3rd floor the egg would actually break because we want the worst case here. Then we take the minimum of number of attempts required for finding the critical floor in worst case of all of the floors in our range and that is the answer.
      This was a little long but I hope this clears things. Thanks

    • @silverbullet_6
      @silverbullet_6 3 ปีที่แล้ว

      thanks bro........saved my time!

    • @nikhil08514
      @nikhil08514 3 ปีที่แล้ว

      Exactly what i was looking for.. Thanks :)

  • @kumarsaurabhraj6917
    @kumarsaurabhraj6917 3 ปีที่แล้ว +232

    Some hints if someone is having a hard time understanding this
    We are given with the number of eggs and the number of floors in the building
    We have to find the minimum number of attempts to find the critical floor with the given number of eggs (we can have leftover eggs)
    If we have only one egg then there is only strategy to keep dropping eggs starting from the bottom till we get to a floor where the egg breaks then we found the critical floor which will be the floor below it
    We do not have any facts on where from dropping from a particular floor wheather the egg breaks or not, for every floor the egg may or may not break
    We have to find the niminum number of attemps it would take to find the threshold floor in the worst case
    What would be best case? We select any floor and drop the egg from it and it does not break and we drop the egg from the floor above it and it does break, then our previous floor will be the critical floor. So in the best case it would take us two attempts and 1 egg to find the critical floor.
    Why just testing for in the middle and halving the floor is not necerrily a good solution? Becuase if you have only one egg left then you would have had to make as many attempts as there are floors to find the critical floor.
    What we are doing here? Our function returns the minimum number of attempts required to find the critical floor with E eggs and F floor (given in arguments), we dont what would the most optiomal floor to make the first attempt from so we are making attempt from every floor, we also dont know if by dropping from a floor wheather the egg would break or not so we test for both the cases, we recursively call the function for the left over floor and eggs, since we assume the worst possible case here and we do not know if from dropping from a floor wheather the egg will break or not, we check for which situation it would take greater number of attempts to find the critical floor and take that one.
    Also since we want the minimum number of attempts to find the critical floor in the worst possible case we take the minimum of the number of attempts required in the worst possible case when the first attempt is made from that fllor and return that as our answer.
    Under standing base cases,
    When there is only one egg then we would have to make as many attempts are there are floors in the worst case to find the critical floor.
    When there is only one floor then we would have to make only one attempt if the egg does not break then its the critical floor and if it does then ground floor is the critical floor, so the number of attempts in this case also would be as many as there are floors.
    When we have no eggs then its not possible to find the critical floor.
    Wehn there are no floors i.e. 0 floors then the group floor will be the critical floor so the answer would be equal to 0 i.e. number of floors.

  • @manasvinsharma1740
    @manasvinsharma1740 2 ปีที่แล้ว +162

    At first, it looks like a problem which can be solved by Binary Search

    • @kartikwar8022
      @kartikwar8022 2 ปีที่แล้ว +2

      It can be solved. But he has given a solution without it. You can optimize further by using binary search

    • @g8dboyplays790
      @g8dboyplays790 ปีที่แล้ว +14

      You can, but that will require infinite eggs to reach the solution. There are limited no. of eggs, so we prefer DP here.

    • @KiyotakaAyanokoji1
      @KiyotakaAyanokoji1 ปีที่แล้ว +2

      @@g8dboyplays790 floors limited hai toh infinite egg kaise lag sakte binary serch me

    • @KiyotakaAyanokoji1
      @KiyotakaAyanokoji1 ปีที่แล้ว +1

      ha at first , it seems ki we were given the value of threshold floor. then we could apply binary serch

    • @AnshiPatel_official
      @AnshiPatel_official ปีที่แล้ว

      Exactly

  • @lakshaychawla78
    @lakshaychawla78 2 ปีที่แล้ว +43

    Adi bhai, mujhe 3-4 months ho gye jb maine first time ye DP ki series start ki thi. Uske baad i went through all of different topic series you taught. Even today sometimes i revise such concepts and questions before some interview or so.
    Mai dil se shukriya krna chaunga for such great concept building exercises ❤️❤️
    and even urge you to make such videos for other concepts as well like backtracking, greedy, graphs etc. People need you👌🏻

  • @kirtipurohit1237
    @kirtipurohit1237 2 ปีที่แล้ว +9

    There are very rare people who teach geniune content on YT without any fake drama or promotion. Wish we have more people like you

  • @visase2036
    @visase2036 2 ปีที่แล้ว +30

    For those who did not get the max and min usage here :
    Consider there are 10 floors in total and we got some x eggs to test .
    Lets say we are at 8th floor now(Problem would start from the 1st floor but consider that we are at 8th) . Here we have two options .
    1. Egg breaks (we are left with x-1 eggs and 7 floors (8th floor is not the critical one so go down by 1 floor)
    2. Egg does'nt break ( we are left with x eggs and 2 floors(9,10 to test) as 8th floor did not break , its waste of time to go down and check other floors as the problem states if the egg doesnt break at one floor it doesnt break on the floors below to it as well ))
    Now here comes the critical point to note , floors to test now are
    1. 1-7 so total of 7 floors(egg broke)
    2. 9-10 so total of 2 floors (egg did not break)
    Whom do you think will give the us the answer Max(attempts (7 floors), (2 floors))) , obviously 7 will yeild more floors to test (Keep in mind , you have to cover all the floors so go by max).
    So that is the reason why we use max(floorsRemainingEggBrokenCase, floorsRemainingEggunbrokenCase)
    And finally here comes the min part :
    Now we tested this by dropping the egg at 8th floor , similarly 3rd floor will yeild us an answer , similarly 5th floor will yeild a diff ans and so on ... till n floors
    Tats y we return the min(egg drop attempts on all the floors)!

  • @0anant0
    @0anant0 4 ปีที่แล้ว +26

    42 of 50 (84%) done! The concept is explained very nicely.

    • @shashishekhar1729
      @shashishekhar1729 3 ปีที่แล้ว +4

      KAUN HAI YE LOG , KAHA SE AATE HAI YE LOG!

    • @aishwarya1895
      @aishwarya1895 2 ปีที่แล้ว +1

      Man your consistency ✌️

  • @lakshsadhwani855
    @lakshsadhwani855 3 ปีที่แล้ว +44

    man you never can explain bad🙈 respect bro for the content you give us , keep growing❤️

    • @ytg6663
      @ytg6663 2 ปีที่แล้ว

      Laksh

    • @manishkumargupta8677
      @manishkumargupta8677 2 ปีที่แล้ว

      Angrez wali English nahi pel diye bhai idhar tum? Hindi me video dekh karke

    • @sleepypanda7172
      @sleepypanda7172 2 ปีที่แล้ว

      @@manishkumargupta8677 isse zyada simple english kya ho skti hai? sahi se toh bola hai vo. Angrez wala kya hota hai. Ek seedhi si line likhi hai

  • @Official-tk3nc
    @Official-tk3nc 4 ปีที่แล้ว +51

    my 12 years old brother saw this video with me now he can solve egg drop problem conceptually:)

    • @TheAdityaVerma
      @TheAdityaVerma  4 ปีที่แล้ว +61

      Haha Really dude? 😂😂 I am hope your not forcing him to watch videos to turn him into a programmer at a young age 😂😅✌️

    • @adarshsharmanit356
      @adarshsharmanit356 4 ปีที่แล้ว +30

      @@TheAdityaVerma Indian Errichto Ban jaayega ,aisa banda 12 saal se hi start kar dega toh , Bhad mein jaaye JEE , Google phod dega aise hi
      😂😂

    • @rahulagarwal8059
      @rahulagarwal8059 4 ปีที่แล้ว +1

      😂😂

    • @AnkitSingh-qz8ix
      @AnkitSingh-qz8ix 3 ปีที่แล้ว +11

      chintu or wott

    • @kaal_bhairav_23
      @kaal_bhairav_23 3 ปีที่แล้ว +1

      bhai wolf gupta se door rakhio apne chote bhai ko

  • @gaunikasrivastava7851
    @gaunikasrivastava7851 2 ปีที่แล้ว +16

    This problem is tougher than scramble string problem 😅😅

  • @starc701
    @starc701 4 ปีที่แล้ว +13

    max is used since ,we have to find guaranteed moves to find the breaking floor, to find gurantee we take worst cases. Nice vdo

  • @prakhargupta5720
    @prakhargupta5720 3 ปีที่แล้ว +9

    for those who didn't understand why we use MAX :-
    assume that for 1 to f floor we put k somewhere in between of 1 and f and we find the answer then it would be the best case. But here we have to check each floor because we have to find the last floor where egg didnt break , not the floor where egg breaks. Hope u undrstand.

    • @harshdeepsingh6768
      @harshdeepsingh6768 3 ปีที่แล้ว +1

      Bro I am struggling to understand this, can you please explain it with an example... like what would have happened if we took min instead of max there.

    • @OmkarGhanekar
      @OmkarGhanekar 2 ปีที่แล้ว +2

      @@harshdeepsingh6768 That is because we don't know if, after choosing to have an attempt from floor k, our egg will break or not and subsequently we dont know which path we will have to take. So we account for whichever path takes us more attempts and then declare that if we choose to drop from k then we will DEFINITELY be able to solve it in 1 + max(recursive calls) attempts. so we calculate this collection of "can definitely solve it in N drops" for all Ks and then pick a K where this value is smallest

  • @ahishnar1568
    @ahishnar1568 3 ปีที่แล้ว +7

    If someone is not able to understand the problem itself then read below explanation.
    Here in this problem we have to find the minimum attempts required to find the threshold floor in worst case.
    For finding this on every step of recursion we have to find one floor or such a floor from which if we drop an egg then we would be required a minimum attempts overall to find threshold floor overall. And if we follow this concept which I just explained on every recursion step till vase case get hit then with magic of recursion we will automatically get most optimized approach in worst case.
    e.g.
    Let's say we have 5 floors as
    5 4 3 2 1
    Then in for loop we have to check one floor or such a floor from which if we drop an egg then we overall we would get minimum attempts.
    So in for loop first we will check for 5 then check for 4 then for 3, 2, 1 and at then end as we required minimum number of attempts so in for loop after finding for was floor that is after assuming each floor as the first floor to drop from, we will take or we will pick that floor from which if we drop an egg then we required minimum attempts.
    And so in for loop we use min function.
    Now the second thing is after dropping an egg 2 things can happen, either egg will break or not break.
    If egg breaks then we will go down to check and if egg does not break then we will go up to check.
    Now as we need minimum attempts in worst case, concentrate here I am saying in worst case we required minimum attempts and so as we are checking for worst case then egg breaking can be the worst case or egg not breaking can be the worst case. But we do not know which is the worst case and so we are cheking for both the cases.
    And so we have to take or use max function here so that we can catch the worst case. And that is why while calling egg break and not break recursion calls which are below the current floor and above the current floor respectively we have to use max function.
    So in short on every step of recursion out of all the floors we have to find one floor or such a floor from which if we drop an egg then we would required minimum attempts.
    I hope this helps :)

    • @AnushkaRai-mr8hh
      @AnushkaRai-mr8hh 2 หลายเดือนก่อน

      Yess! Finally I got it! Thanks!

  • @bhargabnath5781
    @bhargabnath5781 3 ปีที่แล้ว +11

    bhaiya, I'm sure that you you must be unwell atleast a little bit, I hear your voice and feel like this. How can I show you my respect for you? Thank you so so much bhaiya, like every videos, this too is simply lit. Kudos to your dedication, bhaiya!!! :) :) :)

  • @kalyanking1080
    @kalyanking1080 3 ปีที่แล้ว +10

    after seeing this problem my reaction 26:50

  • @MrRavi20khatri
    @MrRavi20khatri 3 ปีที่แล้ว +5

    Wise way to use egg is to make omlet...

  • @rishabhgaurav
    @rishabhgaurav 4 ปีที่แล้ว +23

    And Can you Please List Down the question at least of the topics which you couldn't upload.
    Like
    In the first video you mentioned...
    Fibonacci(7 questions)
    LIS(10 questions)
    Kadane's (6 questions)
    DP on grid(14)
    others(3)
    So that I can complete these topics as well.
    PS: You have a very good and curated playlist.

    • @TheAdityaVerma
      @TheAdityaVerma  4 ปีที่แล้ว +11

      Do not have a list right now Sorry 😕, But will try to upload them as well.

    • @sauravdas7591
      @sauravdas7591 4 ปีที่แล้ว +31

      leetcode.com/discuss/general-discussion/458695/dynamic-programming-patterns> try this, as it contains a no of separate patterns dp

    • @0anant0
      @0anant0 4 ปีที่แล้ว +1

      @@sauravdas7591 Highly underrated comment. Should be pinned on the first or last video of this DP series.

    • @sachinsharma905
      @sachinsharma905 3 ปีที่แล้ว

      @@sauravdas7591 Thanks man.

    • @ahishnar1568
      @ahishnar1568 3 ปีที่แล้ว

      @@sauravdas7591 Thanks man

  • @anshulgoel1940
    @anshulgoel1940 ปีที่แล้ว

    Some people call this as front partitioning and not MCM and I was always confused whats the damn difference. This video made it super clear. Just a small variant of the same thing.

  • @abhishekbajaj109
    @abhishekbajaj109 4 ปีที่แล้ว +6

    If you have a doubt that why we are taking max then let me explain you the question is using you to find minimum no of attempts to find the threshold in worst case. Focus on the word Worst case if we take min there we would not get the answer for the worst case
    for eg take 2 eggs and 2 floors
    1) 1+max(sol(0,0),sol(1,1)) from this you can tell if egg breaks in first floor then its not the worst case here the worst case is 2nd floor so we go to second floor to test it so from there you will see why we used max
    and later to find min attempts we use min .
    i hope this helps.

  • @lj2738
    @lj2738 4 ปีที่แล้ว +8

    bhai may month aa gaya hain ,waiting for new series..& thanks :)

  • @yashmittal9040
    @yashmittal9040 3 ปีที่แล้ว +8

    had to watch this video like to 4 to 5 times to properly understand what is the meaning of worstcase but finally understood

  • @chhaviagarwal7514
    @chhaviagarwal7514 3 ปีที่แล้ว +7

    Loved your way of teaching..Can you please upload videos for remaining topics like kadane's algo and Longest Increasing Subsequence🙏🙏

  • @himanshusoni1512
    @himanshusoni1512 2 ปีที่แล้ว +5

    For 100% certainty, always consider the combination of your BEST and others' WORST Case.

  • @bharatnihar
    @bharatnihar 2 ปีที่แล้ว

    Bhai maja aagaya explaination dekh k.Baith gya dimag m Best tutorial for this question on TH-cam.

  • @pavankumar-cy6mg
    @pavankumar-cy6mg 3 ปีที่แล้ว +3

    .It is not ruled out that the first-floor windows break eggs, nor is it ruled out that the 36th-floor do not cause an egg to break.

  • @nitianthrive6099
    @nitianthrive6099 ปีที่แล้ว +1

    Dil se hats off for your explanation 🫡🫡

  • @ShreyaSingh-vr9qi
    @ShreyaSingh-vr9qi 4 ปีที่แล้ว +12

    Nice explaination !! I was confused a lot about why to choose worst case but now its cleared. Thanks for explaining.

    • @TheAdityaVerma
      @TheAdityaVerma  4 ปีที่แล้ว +10

      I am glad it helped you. Share where ever you can it would help me :P

  • @ankurnarayansingh3031
    @ankurnarayansingh3031 2 ปีที่แล้ว +2

    at 26:53 engineers instinct. 🤣

  • @CricketGalaxy07-18
    @CricketGalaxy07-18 ปีที่แล้ว

    me ye ek problem sikhane aaya tha or puri MCM pertan sikh li thanks sir 🤩🙌🙌

  • @shakshigupta1336
    @shakshigupta1336 ปีที่แล้ว +4

    Why can't we use binary search for e-1 eggs (halfing the floors each time) and then use the last egg one by one for remaining floors?

    • @badabeta6973
      @badabeta6973 9 หลายเดือนก่อน

      I have the same doubt can anyone explain

  • @anantjain1263
    @anantjain1263 3 ปีที่แล้ว +3

    Why we are adding 1 + in max I didn't understand the answer , please help

    • @amanburman9114
      @amanburman9114 3 ปีที่แล้ว +2

      At that iteration, you are dropping an egg to check whether it will break or not. The question asks minimum no. of "attempts", so when you drop an egg, you increase your "count of attempts" by 1. Meaning you "attempted" to check whether egg will break or not. Hope you understand.

  • @udayjordan4262
    @udayjordan4262 2 ปีที่แล้ว +2

    dakho dakho ma simple samjha ta hu manlo do banda h wo ak bar ak building ma gai 20 floors ki h thik ak na decide kia ki ma 15th wala (k in his case)floor sa faka ta hu anda aur dusra na bola thik h ma 7th(k in his case) floor sa anda fak ta hu 15 th wala banda ka anda tut gaya aur 7th wala ka nahi tuta thik ab 7th wala banda bola thik h phir ma upar jata hu kyuki nicha jana ka to koi fayada nahi h aur 15th wala na bola ma nicha wala floor pa jaka attempt karta hu kyuki upar jana ka to koi fayada nahi h ab kya hua dono ko 9th floor threshold mil gaya but hua kya jo 7th floor wala banda tha usna kam attempts kia aur jo 15th floor wala banda tha usna jayada kia to worst case ma 15th floor wala ka attempts count hoga thik ab asa hi manlo ya do banda 3 bar try karta h but is time alag k laka aur 3 bar manlo worst case ma ak ka 10 attempts laga dusri bar usi ka 12 attempts laga teesri aur akhri bar 7 attempts laga ...manlo maina wo pahla wala banda ka naseeb itna kharab usi ka ya sara attempts k fal h ab 10,12,aur 7 ma sa minimum kaun sa h 7 wala h to bass wahi return karana h

  • @harshchiki7796
    @harshchiki7796 2 หลายเดือนก่อน

    you built the building some many times - it felt like a civil engineering problem than the computer science problem some times.

  • @kumarsaurabhraj2538
    @kumarsaurabhraj2538 3 ปีที่แล้ว +2

    I think there should be another base case, when e == 0 then return INT_MIN or -1 since its not possible to find the number of attempts to find the critical floor if we have no eggs so we would want such cases to be eliminated in out max() comparison.

  • @RanjeetSingh-st2vu
    @RanjeetSingh-st2vu 3 ปีที่แล้ว +5

    Sir in this problem why we can't use binary search?

  • @ritishdhiman26
    @ritishdhiman26 4 ปีที่แล้ว +4

    best lectures on dp , thanks :)

  • @akhiranandanpallepogu7337
    @akhiranandanpallepogu7337 9 หลายเดือนก่อน +1

    Bro casually dropped f bomb at 26:48 😂

  • @prakhartiwari8153
    @prakhartiwari8153 4 ปีที่แล้ว +16

    bro eagerly waiting for other patterns like Fibonacci series etc,,,,, :(

  • @iamnoob7593
    @iamnoob7593 8 วันที่ผ่านมา

    Thanks very good explanation

  • @satwikjain6177
    @satwikjain6177 ปีที่แล้ว

    if you understand the problem statement clearly you can start from here 11:40

  • @shiwamjaiswal9653
    @shiwamjaiswal9653 4 ปีที่แล้ว +10

    What I have understood from the "worst case" is if the no of attempts are maximum by breaking the eggs to find the threshold floor (i.e. by going down) then we keep breaking till we have one egg remaining. Else we don't break any eggs and go to the top most floor and count the number of attempts to reach there. And in the final answer we take maximum of both the answers. That means we never stop in between the floors. This is the reason why we take Base Conditions :
    if(e==1) return f; // if we have one egg left we simply return the number of floors given considering that in worst case we don't break any egg and reach to the given number of floor.
    if(f==0||f==1) return f; // if we have only one floor/No floor then that is the worst case regardless of the number of eggs we have.
    Can anyone validate my thought process?

    • @ekanshsharma4293
      @ekanshsharma4293 4 ปีที่แล้ว

      Yes it's completely correct

    • @devendrasingh4776
      @devendrasingh4776 4 ปีที่แล้ว +3

      We are stopping at every floor because for each floor we again have to think for two case s

  • @codebot1027
    @codebot1027 3 ปีที่แล้ว +1

    Thank You Soo Much Aditya, You Explained It Very Well...

  • @ankoor
    @ankoor 4 ปีที่แล้ว +7

    Python: Recursive
    def Solve(eggs, floors):
    if floors == 0 or floors == 1:
    return floors
    if eggs == 1:
    return floors
    count = float('inf')
    for i in range(1, floors+1):
    temp = 1 + max(Solve(eggs, floors-i), Solve(eggs-1, i-1))
    count = min(count, temp)
    return count
    eggs = 3
    floors = 5
    attempts = Solve(eggs, floors)
    print('# of attempts: ', attempts)

  • @maximus6448
    @maximus6448 3 ปีที่แล้ว +1

    N^ 2 solution :
    def superEggDrop(self, egg: int, floor: int) -> int:
    dp = [[0]*(egg+1) for i in range(floor+1)]
    for i in range(1 , floor+1):
    for j in range(1 , egg + 1):
    # two case arises
    starting from ground floor
    # when we are moving from bottom to top either
    # egg breaks or not if egg breaks we decrease egg count
    # else not and 1 is increasing the number of attempt after
    # every floor when egg breaks.
    # dp[i-1][j-1] when egg breaks
    # dp[i-1][j] when egg does not break.
    dp[i][j] = 1 + dp[i-1][j] + dp[i-1][j-1]
    if dp[i][j] >= floor: return i

  • @madhurbhargava
    @madhurbhargava 4 ปีที่แล้ว +18

    Bro, you need to use binary search in place of your for loop, otherwise this will give TLE despite memoization on LC.

    • @mainaksanyal9515
      @mainaksanyal9515 4 ปีที่แล้ว +8

      Even I find it similar to binary search problem. We can split it in two halfs always to check if the egg breaks or not. And lets suppose we are at mth position in doing so and have only 1 more egg left. Then worst case can be (n-1)+(m-1) cases. And if f is smaller that 2^n then it is more easy to find. I don't get why we have to make this ques analogous to MCM!?

    • @madhurbhargava
      @madhurbhargava 4 ปีที่แล้ว +1

      @@mainaksanyal9515 That is actually a better/more efficient way of doing this. Although for small inputs, bhai ne bahut accha samjhaya hai.

    • @srini9
      @srini9 4 ปีที่แล้ว +1

      बहुत बदिया भाई

    • @manthoshn4386
      @manthoshn4386 3 ปีที่แล้ว +16

      binary search will work when you have unlimited no of eggs for trials,,, here we have limited eggs

    • @madhurbhargava
      @madhurbhargava 3 ปีที่แล้ว

      @@manthoshn4386 do enlighten me why the binary search should not work on limited I/p. Also, do show me a piece of code which passes on lc without a d&c algo for this problem.

  • @gauravdixit2288
    @gauravdixit2288 4 ปีที่แล้ว +2

    @Adi bhai can u please tell the time complexity of recursive version and also please discuss the n^logn approach

  • @motivational_dosee
    @motivational_dosee 2 ปีที่แล้ว +1

    This problem seems very simple but logic is too deep and confusing 💀

  • @vatsalagarwal2466
    @vatsalagarwal2466 4 ปีที่แล้ว +3

    I have a major doubt, We are calling solve(e, f). Doesnt it matter, what length of last K we have already checked ? Why the answer always depends on the number of floors and not the floor number. Please clear.

    • @akhilmanoj5512
      @akhilmanoj5512 4 ปีที่แล้ว +3

      When the egg breaks from the k-th floor, we consider a subproblem with the height of the building as k. Similarly, when it doesn't break from the k-th floor, you can consider another subproblem with the ground being at the k-th floor level. Due to this fact, the floor number doesn't play a role in the solution.

  • @amanchauhan7451
    @amanchauhan7451 3 ปีที่แล้ว +3

    Do this Problem is practically possible? How we can determine that the minimum no of Steps for finding Threshold floor for Floors =100 and Eggs = 2 is 14 ???

    • @AryanGairola-th3qc
      @AryanGairola-th3qc 19 วันที่ผ่านมา

      go to 50th floor drop it if it breaks strat from 1 because now you rae left with 1 only
      if it doesnot break from 50 th than go to 75 and repeat the process
      but as you said it breaks you will ned 15 steps
      first to got to 50 and then 1 byb one till 14

  • @mickyman753
    @mickyman753 3 ปีที่แล้ว +1

    the critical floor can be any floor and it is not any specific floor, worst case main kisi bhi random floor se start krne pr kitne minimum attempt lgenge , aise sab starts se no. of attempts ka minimum nikalna hai

  • @tanujaSangwan
    @tanujaSangwan 6 วันที่ผ่านมา

    All these questions are literally so tough. scrambled eggs, egg dropping, expression to True/False. Do people actually solve it in the first go? Or I am just dumb.

  • @deepankaradhikari5405
    @deepankaradhikari5405 4 ปีที่แล้ว +4

    In mid of this video, I realize ki abb pen ghumana aa gya

  • @bhavneetsingh2000
    @bhavneetsingh2000 3 ปีที่แล้ว +1

    I still didn't get why we maximized for worst case?

  • @nitinchandel8103
    @nitinchandel8103 3 ปีที่แล้ว +1

    can some body tell me what is the role of no. of egg here , even if we drop a single egg it is considered as an attempt

  • @saurabhthakur2718
    @saurabhthakur2718 ปีที่แล้ว

    very simple explanation, thank you !

  • @roliagrawal3124
    @roliagrawal3124 3 ปีที่แล้ว +1

    @Aditya Verma I am not getting why we are taking worst case?

    • @navjyotbhele8307
      @navjyotbhele8307 3 ปีที่แล้ว +1

      because in best case we only need 2 attempts. That is we choose a random floor luckily and the egg is not broken from that floor(1st attempt) and from the floor on top of it, egg breaks(2nd attempt) that is the curr floor is critical floor. Hence we require 2 attempts only. hence we are asked to to take worst case

  • @bhavyaaggarwal8558
    @bhavyaaggarwal8558 2 ปีที่แล้ว +4

    26:50 iconic word of this video😂😂

  • @rkalpeshk
    @rkalpeshk 3 ปีที่แล้ว +2

    JAVA CODE :
    static int fun(int egg, int floor) {
    if (floor == 0 || floor == 1)
    return floor;
    if (egg == 1)
    return floor;
    int min = Integer.MAX_VALUE;
    for (int k = 1; k temp)
    min = temp;
    }
    return min;
    }

  • @pqazx1
    @pqazx1 4 ปีที่แล้ว +2

    how to print the ans for each floor??

  • @dinakarmaurya8000
    @dinakarmaurya8000 3 ปีที่แล้ว +1

    Is it possible to try using binary search technique? Try to fall from middle?

  • @SurjitSingh14-c6i
    @SurjitSingh14-c6i 3 ปีที่แล้ว +2

    Can't it be solved by binary search

  • @pavankumar-cy6mg
    @pavankumar-cy6mg 3 ปีที่แล้ว +2

    what do you mean by break at any floor in coding

  • @avmovies7930
    @avmovies7930 หลายเดือนก่อน

    Please complete full DP series

  • @Shobhitgupta01
    @Shobhitgupta01 7 หลายเดือนก่อน

    I Still have problem understanding why we are using MCM technique here.
    MCM us generally used when we need to create subgroups in an array/string and calculate something. wg A1A2A3 => (A1)(A2A3), or T&F|T => (T&(F|T)). K is meant to create a partition and we recursively find partitions on existing ones.
    Can't visualize here why we need to do this and why cant we use binary search. Please help

  • @arjunkhanna1803
    @arjunkhanna1803 2 ปีที่แล้ว +1

    Can we use binary search on answer?

  • @csinfoplus3788
    @csinfoplus3788 5 หลายเดือนก่อน

    Great explanation ...

  • @sujayshanbhag2055
    @sujayshanbhag2055 ปีที่แล้ว

    why find out minimum of worst cases though?
    it is easy to understand looking at the code, that it is taking minimum of worst cases.
    But why tho?
    I understand that to be sure we might need to calculate max of both recursion calls, but why take minimum of all such cases.
    shouldnt we also take worst case here to be sure that a solution can be reached in the given number of drops, any way we try to start to drop.

  • @oqant0424
    @oqant0424 2 ปีที่แล้ว

    though took some time to understand .....but the explanation was awesome!

  • @abhinavgupta8098
    @abhinavgupta8098 4 ปีที่แล้ว +4

    sir please backtracking

  • @vaibhavjadhav8987
    @vaibhavjadhav8987 4 ปีที่แล้ว +2

    great video bro... really helpful....but 50th floor se egg kon drop karta hai yaar(just for fun)

    • @TheAdityaVerma
      @TheAdityaVerma  4 ปีที่แล้ว +38

      Thanks !!
      Placement k liye sb krna pdhta h bhai 😂😂

    • @chiragkushwaha546
      @chiragkushwaha546 4 ปีที่แล้ว +1

      @@TheAdityaVerma 🤣🤣🤣

  • @kapil6392
    @kapil6392 3 ปีที่แล้ว

    why can't we use simple binary search till no: of eggs left is 1 and then for the last egg we can use simple loop within the range.

  • @kartiksaini5619
    @kartiksaini5619 2 ปีที่แล้ว +1

    i think this can be solved using binary search as well ,kindly correct me if i'm wrong ,cuz i haven't tried solving it using bsearch but while going through i got an idea

    • @pranjal-barnwal
      @pranjal-barnwal ปีที่แล้ว

      Binary Search will pass only for few testcases where eggs are sufficient (i.e. number of eggs >= log(number of floors) ).
      Like if eggs = 2 & floors =100, you can solve this with binary search as you would need in worst case 7 eggs

  • @dhruvbhanderi3407
    @dhruvbhanderi3407 2 ปีที่แล้ว +1

    can't we apply binary search?

  • @__RohitDevar
    @__RohitDevar 3 ปีที่แล้ว +2

    26:49 😄😄

  • @mahipalsingh-yo4jt
    @mahipalsingh-yo4jt 3 ปีที่แล้ว

    great explanation sir ........

  • @girikgarg8
    @girikgarg8 2 ปีที่แล้ว

    I had a doubt here.... in MCM pattern we usually consider invalid input... so here why did we consider smallest valid input?

  • @tanmay6441
    @tanmay6441 2 ปีที่แล้ว +1

    bhaiya ham middle se kyun nhi faik sakte? usme bina mcm ke hojayega binary search jese kuch

  • @mathematicsquestions
    @mathematicsquestions 2 ปีที่แล้ว

    It seems recursion rather than dynamic programming. Which part of it defines dynamic programming used? Please explain.

  • @amlansengupta9178
    @amlansengupta9178 4 ปีที่แล้ว +5

    Guys, my intuition was:
    for(int k=1;k

    • @appinirohan3335
      @appinirohan3335 4 ปีที่แล้ว +3

      In every call we are passing the number of eggs left and the number of floors left to check. So after checking k'th floor if you pass k+1 you are increasing the. number of floors i.e(k+1) ,whereas (floor - k) gives you the remaining floors .

    • @wholeegg
      @wholeegg 4 ปีที่แล้ว

      @@appinirohan3335 Thanks Man. Going through the comment for the doubts really helps a lot 😀.

  • @siddharthkeshri5649
    @siddharthkeshri5649 3 ปีที่แล้ว

    I think a best approach of this problem can come from binary search it's just a hunch not checked till now

    • @Bdixit
      @Bdixit 3 ปีที่แล้ว

      I was also thinking somewhat this in my mind.

    • @siddharthkeshri5649
      @siddharthkeshri5649 3 ปีที่แล้ว

      @@Bdixit yes Bro a approch exists of Binary search and its the best one 😅

  • @Finimals
    @Finimals ปีที่แล้ว

    Why cant we do it from Binary search eg 14 floors, worst case is 14th floor, so first solve at 7 and it will break , then solve 11 , then 13 and then 14 ans 4 attempts

  • @learntogrow6132
    @learntogrow6132 ปีที่แล้ว

    this ques would be much practical if thereshold was given and we need to calculate the ways

  • @David-mk8kh
    @David-mk8kh ปีที่แล้ว

    I understood all the problems before with a great ease, but this problem is a bit different and confusing then all the previous problmes😵‍💫😵‍💫🥴😢😬

  • @abhisheksuryavanshi9675
    @abhisheksuryavanshi9675 4 ปีที่แล้ว +1

    Please upload new videos..May is about to get over

  • @melbinthomas2199
    @melbinthomas2199 4 ปีที่แล้ว

    Awesome explanation

  • @sonianarendramodi2605
    @sonianarendramodi2605 2 ปีที่แล้ว

    26:49 nice

  • @aanchalsingh5782
    @aanchalsingh5782 3 ปีที่แล้ว

    Why can't we apply binary search in this ??

  • @prayagpatel9136
    @prayagpatel9136 2 ปีที่แล้ว

    worst case basically implies "guarantee of k we have found" right?

  • @prakritidevverma
    @prakritidevverma 3 ปีที่แล้ว +2

    did you say fuck ?

  • @praveenkumar-er6ze
    @praveenkumar-er6ze ปีที่แล้ว

    how we can say when floor is zero then return f

  • @karanamdharneesh4279
    @karanamdharneesh4279 ปีที่แล้ว

    first time when i tried to approach the problem i thought k would always be ceil(f/2). Can someone try to disprove this approach, even though i know considering k variable gives hold of all types of solution possible or more generic one.

  • @cripz4203
    @cripz4203 4 ปีที่แล้ว +3

    Can we get more optimised answer if we iterate k just like we do for binary search rather than linear.

    • @0anant0
      @0anant0 4 ปีที่แล้ว

      Yes, since the floors are already a 'sorted array'. If broken >= unbroken, hi = mid, else lo = mid+1

    • @aishuo07
      @aishuo07 3 ปีที่แล้ว

      nope

    • @Kuriocity
      @Kuriocity 3 ปีที่แล้ว +2

      For Binary Search, we ll require log n eggs but here we have limited

  • @sleepypanda7172
    @sleepypanda7172 2 ปีที่แล้ว

    You repeat a lot! otherwise great content.

  • @s_ubh
    @s_ubh 5 หลายเดือนก่อน

    I tried! Every time breaks at first floor. I think the answer is very simple. Threshold floor = ground floor. 😂 L

  • @herculean6748
    @herculean6748 ปีที่แล้ว

    ans could be always near around f/2, because it has to consider the worst case, I am not able to understand what I am missing, can anyone help me

  • @ARYAN_BAJPAI_IIT_BHU
    @ARYAN_BAJPAI_IIT_BHU 2 หลายเดือนก่อน

    can we use binary search

  • @manojnavinjamuri5867
    @manojnavinjamuri5867 ปีที่แล้ว +1

    thank you soo muchhh

  • @anjalichoudhary5467
    @anjalichoudhary5467 4 ปีที่แล้ว +3

    Thank you :)

    • @TheAdityaVerma
      @TheAdityaVerma  4 ปีที่แล้ว +3

      You're welcome!

    • @bharataaryavrat4067
      @bharataaryavrat4067 3 ปีที่แล้ว

      can you see my mistake ,i am geeting wrong answer
      #include
      using namespace std;
      #define ll long long
      // string dp[4001][4001];
      vectordp(4001,vector(4001,""));

      int main()
      {
      string s1,s2;
      cin>>s1>>s2;
      ll n=s1.length();
      ll m=s2.length();
      for(ll i=0;i

  • @Sunny-cx8ki
    @Sunny-cx8ki 4 ปีที่แล้ว +6

    26:50😂😂😂

    • @samkr200
      @samkr200 3 ปีที่แล้ว +3

      Yours and my humour is broken

  • @gouravchalotravlog
    @gouravchalotravlog 2 ปีที่แล้ว

    Ya kush binary search jasa question lag raha ha kya is ma BS lag sakti ha ? bhiya ji