Box Stacking Problem | Dynamic Programming | LIS
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
This channel deserves a million subscribers !
Thanks 😊
Thanks for the intuition. The key was in base area, I was so confused on that point.
you covered each and every possible doubt. Hats off sir
Thanks
thank you making solution of this.. problem, I have easily understood concept In one go..
That was very helpful. Thanks lots!
Welcome :)
Your explanation is incredibly well.
Thanks
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.
Yeah.. Exactly
Google krlo
Supper visual explanation with good intuition Awesome 👌👌🔥🔥
Thanks
Excellent brother!!
Amazing explanation!
amazing.. I just love your explanation
Thanks :)
your explanations are very nice. one suggestion: try to attach question links in descriptions so that we can go and practice first
Sure 👍🏼
Amazing explaination! Keep doing the good work!
Thanks
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.
Best channel for DSA
:)
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
Yes you will be 😃
@@techdose4u yes bro. Was able to do both gfg and leetcode varient
@@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?
such a great explanation thaNKS
:)
really nice explanation bro. I liked it, thanks for explaining so well. Keep doing the good work!
Hardest problem I have seen till now
This was hard with lots of constraints.
Awesome Explaination
Thanks
super cool!!
🤗
Nice
nice explanation!!:):):):) .. can we further reduce the time complexity to O(NlogN) ?
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
At 10:35 config 1 is invalid as top most box has l=7 which is > than l=6 of box below it.
Correct observation
How to solve this if we can use a box only once in any desired configuration?
Sir, Please make a video series for number theories....
I will make once I am done with placement series.
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]
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?
is this problem anywhere on leetcode or other platforms?
Bhalaa kaam kar rahe hai ye
:)
Sir I am not able to understand the part where you set the width to be minimum of height and width
That was set to make sure that width is the smaller of the 2 dimensions (bacause rotation is possible)
Thank you Sir understood :)
Do they ask such hard questions in coding interview round for SDE 1 position ?
Generally only medium questions. No hard ones.
@@techdose4u Thank You ❤️
No problem :)
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.
sorry it's in the last part of video. Thank you!
No problem.
I saw your 2 months preparation video can you suggest a website to practice in javascript because gfg does not have js resorces
Try interviewbit. Check if JavaScript is there
@@techdose4u thanks in that which level problems should i solve?
@@lakshmis5860 Solve all the questions. All are good problems filtered from leetcode.
@@techdose4u thanks a lot for the reply
@@techdose4u And also please can you say important topics to crack kickstart please reply
your videos are really helpful man . can you make video on leetcode 464. Can I Win
Thanks. I will try.
Please can you say important topics to crack kickstart please reply
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.
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;
Why can't we sort based on length and width in starting itself?
Edit: We can do this but then we would have to use all 6 permutations
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));
}
its taking a lot of effort to understand your version can u break it much simpler in explaining?
I will try
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).
what he means is the area of base. (WxL) = (LxW) . So in that case you have only 3 possible unique base out of 6.
@@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
ok its covered at the end
lis[i]
It's simply the LIS algo. Check out my LIS video where I had explained this in detail.
Sir ye lis algo aapne lds mein kyu lga dia
Very poorly explained monotonously without any enthusiasm.
A person at 3 O'Clock night doesn't really have a lot of enthusiasm left. What do you need 🤔
@@techdose4u some people forget how to appreciate...chill!!! btw Great video!!
@@techdose4u You explained it very well. He's being rude 😶
If enthusiasm is what you need when being explained a problem then you are in the wrong career domain,my friend.
@TECHDOSE I think he didn't know coding otherwise he won't comment like this btw great explanation.Your videos are very helpful sir.