Box Stacking Problem | Dynamic Programming | LIS

Sdílet
Vložit
  • čas přidán 27. 07. 2024
  • This video explains a very important dynamic programming interview problem which is the box stacking problem.This is a very famous problem which is based on the longest increasing subsequence.In this problem, we are required to pile up boxes one on top of the other so that you form the maximum height of box pile-up.I have first explained the problem using simple examples and then I have explained all the observations and constraints.This helps in building intuition to solve the problem.I have shown how this problem is a variation of longest increasing subsequence which is the same as the longest decreasing subsequence.I have also shown the dry run of the problem followed by code walk through at the end. CODE LINK is present below as usual. If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful...CYA :)
    ========================================================================
    Join this channel to get access to perks:
    / @techdose4u
    INSTAGRAM : / surya.pratap.k
    SUPPORT OUR WORK: / techdose
    LinkedIn: / surya-pratap-kahar-47b...
    WEBSITE: techdose.co.in/
    TELEGRAM Channel LINK: t.me/codewithTECHDOSE
    TELEGRAM Group LINK: t.me/joinchat/SRVOIxWR4sRIVv5...
    =======================================================================
    CODE LINK: gist.github.com/SuryaPratapK/...
    USEFUL VIDEOS:-
    Longest Increasing Subsequence (LIS): • Longest increasing sub...
    Longest Common Subsequence: • Longest common subsequ...
    #dp #lis #boxstacking

Komentáře • 91

  • @himanshidixit6406
    @himanshidixit6406 Před 3 lety +16

    This channel deserves a million subscribers !

  • @Joyddep
    @Joyddep Před 2 lety

    Thanks for the intuition. The key was in base area, I was so confused on that point.

  • @kannupriyarana4971
    @kannupriyarana4971 Před 3 lety +2

    you covered each and every possible doubt. Hats off sir

  • @pawanlok1776
    @pawanlok1776 Před rokem

    thank you making solution of this.. problem, I have easily understood concept In one go..

  • @chrisogonas
    @chrisogonas Před 3 lety +2

    That was very helpful. Thanks lots!

  • @MahirHasancse21
    @MahirHasancse21 Před 3 lety +2

    Your explanation is incredibly well.

  • @ismail8973
    @ismail8973 Před 3 lety +9

    Your explanation and intuitions about the problems are really great. A small suggestion, Providing links to this problems will be helpful, so that we can try to solve it before seeing the vedio.

  • @bharatiyadharohar
    @bharatiyadharohar Před 3 lety +4

    Supper visual explanation with good intuition Awesome 👌👌🔥🔥

  • @prateekpandey4781
    @prateekpandey4781 Před 2 lety

    Excellent brother!!

  • @shreyashachoudhary480

    Amazing explanation!

  • @rishabhkumar8115
    @rishabhkumar8115 Před 3 lety +1

    amazing.. I just love your explanation

  • @mukulbahedia645
    @mukulbahedia645 Před 2 lety +5

    your explanations are very nice. one suggestion: try to attach question links in descriptions so that we can go and practice first

  • @kishores5121
    @kishores5121 Před 3 lety +5

    Amazing explaination! Keep doing the good work!

  • @Sunny-qq6un
    @Sunny-qq6un Před 3 lety

    seriously the important content which never found in any youtube channel, I found at this place, you deserve more views and subscribers , I have stuck in this problem for past one day but after I come here you know what happen....., thank you so much from bottom of my heart.

  • @bharatandsanatandharma3389

    Best channel for DSA

  • @dayanandraut5660
    @dayanandraut5660 Před 2 lety +2

    This problem (gfg and leetcode varient) was a headache to me. Your explanation has made it easier to understand. Hopefully i will be able to solve it now

    • @techdose4u
      @techdose4u  Před 2 lety +1

      Yes you will be 😃

    • @dayanandraut5660
      @dayanandraut5660 Před 2 lety +1

      @@techdose4u yes bro. Was able to do both gfg and leetcode varient

    • @ShashankRustagiCSE
      @ShashankRustagiCSE Před 2 lety

      @@techdose4u bro how will you tackle striver, he is so so confident ki his dp series is going to be best. I support you. WHat do you say?

  • @madIndianHindu
    @madIndianHindu Před 2 lety +1

    such a great explanation thaNKS

  • @akshayyadav30
    @akshayyadav30 Před 2 lety

    really nice explanation bro. I liked it, thanks for explaining so well. Keep doing the good work!

  • @RTX_valorant
    @RTX_valorant Před 3 lety +5

    Hardest problem I have seen till now

    • @techdose4u
      @techdose4u  Před 3 lety +1

      This was hard with lots of constraints.

  • @sachinjindal4921
    @sachinjindal4921 Před 3 lety +1

    Awesome Explaination

  • @peaceandlov
    @peaceandlov Před 3 lety +1

    super cool!!

  • @smartwork7098
    @smartwork7098 Před rokem

    Nice

  • @priyabratasingha174
    @priyabratasingha174 Před 3 lety

    nice explanation!!:):):):) .. can we further reduce the time complexity to O(NlogN) ?

  • @anantjain1263
    @anantjain1263 Před 3 lety +2

    Sir aapne jo do orientation btai thi usme hum h,w,l ko w,h,l ya phir l,w,h se replace kr skte h but aap 32:00 pe to height constant rkhke l,w ko replace krre ho which is not possible in any orientation ?? Can anyone explain

  • @iSumitYadav
    @iSumitYadav Před 3 lety +4

    At 10:35 config 1 is invalid as top most box has l=7 which is > than l=6 of box below it.

  • @niveshduppalapudi6616

    How to solve this if we can use a box only once in any desired configuration?

  • @ArifulIslam-im7wr
    @ArifulIslam-im7wr Před 3 lety +1

    Sir, Please make a video series for number theories....

    • @techdose4u
      @techdose4u  Před 3 lety +1

      I will make once I am done with placement series.

  • @anantjain1263
    @anantjain1263 Před 3 lety

    Sir ye lis vali condition smjh ni aai iske through hum lds kaise bnare h , I am asking about lis[i] < lis[j] +arr[i],h iss hum lds nikalre h na to aapne array ka naam lis kyu rkha or ha agar lds nikalre h to ye thik h but sir hum khudse kaise sochenge like last question mein aapne lis k lie lis[i]

  • @syedyaser8753
    @syedyaser8753 Před 3 lety

    Your explaination skill are way too good. It teaches how to analyse the problem and approach towards the solution. Very helpful. Thanks a lot for making this. Keep up the good work.
    Btw can you tell which app you use for this blackboard?

  • @fdddd2023
    @fdddd2023 Před rokem

    is this problem anywhere on leetcode or other platforms?

  • @devprakash5320
    @devprakash5320 Před 3 lety +1

    Bhalaa kaam kar rahe hai ye

  • @harshgupta1913
    @harshgupta1913 Před 3 lety +5

    Sir I am not able to understand the part where you set the width to be minimum of height and width

    • @techdose4u
      @techdose4u  Před 3 lety

      That was set to make sure that width is the smaller of the 2 dimensions (bacause rotation is possible)

    • @harshgupta1913
      @harshgupta1913 Před 3 lety

      Thank you Sir understood :)

  • @shaistaperween7920
    @shaistaperween7920 Před 3 lety +2

    Do they ask such hard questions in coding interview round for SDE 1 position ?

  • @Sky-nt1hy
    @Sky-nt1hy Před 3 lety +2

    Sir, thank you for your video!
    I have a question. in 11:40 , transformation of (10,32,12) can be (12,32,10), (32,12,10) but can it also be (32,10,12)? cuz rotation with respect to y axis also works.

    • @Sky-nt1hy
      @Sky-nt1hy Před 3 lety +1

      sorry it's in the last part of video. Thank you!

    • @techdose4u
      @techdose4u  Před 3 lety

      No problem.

  • @lakshmis5860
    @lakshmis5860 Před 3 lety +1

    I saw your 2 months preparation video can you suggest a website to practice in javascript because gfg does not have js resorces

    • @techdose4u
      @techdose4u  Před 3 lety

      Try interviewbit. Check if JavaScript is there

    • @lakshmis5860
      @lakshmis5860 Před 3 lety

      @@techdose4u thanks in that which level problems should i solve?

    • @techdose4u
      @techdose4u  Před 3 lety

      @@lakshmis5860 Solve all the questions. All are good problems filtered from leetcode.

    • @lakshmis5860
      @lakshmis5860 Před 3 lety

      @@techdose4u thanks a lot for the reply

    • @lakshmis5860
      @lakshmis5860 Před 3 lety

      @@techdose4u And also please can you say important topics to crack kickstart please reply

  • @thegreatsilence1081
    @thegreatsilence1081 Před 3 lety +1

    your videos are really helpful man . can you make video on leetcode 464. Can I Win

  • @lakshmis5860
    @lakshmis5860 Před 3 lety

    Please can you say important topics to crack kickstart please reply

  • @bharathirv8479
    @bharathirv8479 Před 3 lety

    can you please solve this problem in an efficient way, i can able to solve it n2 time complexity or please tell me which algo is best to solve.
    Given a two dimensional array of string like => completed


    Where the first string is “child”, second string is “Father”. And given “ronaldo” we have to find his no of grandchildren Here “ronaldo” has 2 grandchildren. So our output should be 2.

    • @ponrajkumarp6777
      @ponrajkumarp6777 Před 3 lety

      make mapm;
      here m.first is father and m.second is vector of sons
      then add size of all the sons of son.
      int grandChild;
      for(string s:m[key])
      grandChild+=m[s].size();
      return grandChild;

  • @vankshubansal6495
    @vankshubansal6495 Před 2 lety

    Why can't we sort based on length and width in starting itself?

    • @vankshubansal6495
      @vankshubansal6495 Před 2 lety

      Edit: We can do this but then we would have to use all 6 permutations

    • @vankshubansal6495
      @vankshubansal6495 Před 2 lety

      Attaching code for reference:
      int maxHeight(int height[], int width[], int length[], int n) {
      // Using set to avoid duplicates
      set shapes;
      for(int i = 0; i < n; i++) {
      shapes.insert({height[i], width[i], length[i]});
      shapes.insert({height[i], length[i], width[i]});
      shapes.insert({length[i], height[i], width[i]});
      shapes.insert({length[i], width[i], height[i]});
      shapes.insert({width[i], length[i], height[i]});
      shapes.insert({width[i], height[i], length[i]});
      }
      vector dimensions(rbegin(shapes), rend(shapes));
      n = dimensions.size();
      vector dp(n);
      dp[0] = dimensions[0][2];
      for(int i = 1; i < n; i++) {
      int maxAns = 0;
      for(int j = i - 1; j >= 0; j--) {
      if(dimensions[i][0] < dimensions[j][0] && dimensions[i][1] < dimensions[j][1]) {
      maxAns = max(maxAns, dp[j]);
      }
      }
      dp[i] = maxAns + dimensions[i][2];
      }
      return *max_element(begin(dp), end(dp));
      }

  • @bhumberg3243
    @bhumberg3243 Před 3 lety +1

    its taking a lot of effort to understand your version can u break it much simpler in explaining?

  • @AnmolSingh-rf3zt
    @AnmolSingh-rf3zt Před 2 lety

    A cuboid can have 6 bases not 3. (W x L) , (L x W) , (H x W) , (W x H) , (L x H) , (H x L).

    • @ramakantasamal7482
      @ramakantasamal7482 Před 2 lety

      what he means is the area of base. (WxL) = (LxW) . So in that case you have only 3 possible unique base out of 6.

    • @AnmolSingh-rf3zt
      @AnmolSingh-rf3zt Před 2 lety

      @@ramakantasamal7482 eg: [w1=11, l1=9 , w2=10, l2=20]
      let's say here B1w2) we consider B1 invalid and remove it bcs w1 cannot fit on top of w2.
      Instead what we could have done is rotate the cuboid such that w1=9 and l1=11. now all the conditions hold true so the cuboid should be valid. (B1

    • @AnmolSingh-rf3zt
      @AnmolSingh-rf3zt Před 2 lety

      ok its covered at the end

  • @syedkaja2045
    @syedkaja2045 Před 3 lety +1

    lis[i]

    • @techdose4u
      @techdose4u  Před 3 lety +1

      It's simply the LIS algo. Check out my LIS video where I had explained this in detail.

    • @anantjain1263
      @anantjain1263 Před 3 lety

      Sir ye lis algo aapne lds mein kyu lga dia

  • @Praveenkr94
    @Praveenkr94 Před 3 lety

    Very poorly explained monotonously without any enthusiasm.

    • @techdose4u
      @techdose4u  Před 3 lety +8

      A person at 3 O'Clock night doesn't really have a lot of enthusiasm left. What do you need 🤔

    • @harshyadav5162
      @harshyadav5162 Před 3 lety +3

      @@techdose4u some people forget how to appreciate...chill!!! btw Great video!!

    • @shaistaperween7920
      @shaistaperween7920 Před 3 lety +2

      @@techdose4u You explained it very well. He's being rude 😶

    • @sachinsharma905
      @sachinsharma905 Před 3 lety +2

      If enthusiasm is what you need when being explained a problem then you are in the wrong career domain,my friend.

    • @konakandlarohith6681
      @konakandlarohith6681 Před 3 lety

      @TECHDOSE I think he didn't know coding otherwise he won't comment like this btw great explanation.Your videos are very helpful sir.