DP 23. Unbounded Knapsack | 1-D Array Space Optimised Approach

  Рет қаралды 139,787

take U forward

take U forward

Күн бұрын

Lecture Notes/C++/Java Codes: takeuforward.o...
Problem Link: bit.ly/3IvPdXS
Pre-req for this Series: • Re 1. Introduction to ...
a
Make sure to join our telegram group for discussions: linktr.ee/take...
Full Playlist: • Striver's Dynamic Prog...
In this video, we solve the problem of minimum coins. We start with memoization, then tabulation, then two-row space optimization. This problem is the seventh problem on DP on Subsequences Pattern. Please watch DP 14 before watching this.
If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.o...
You can also get in touch with me at my social handles: linktr.ee/take...

Пікірлер: 517
@sandeeperukulla498
@sandeeperukulla498 3 жыл бұрын
Hey Striver, I solved the problem in all 3 approaches without watching the video. All credit goes to you, Thanks a lot. You are the best.
@anuragpandey8165
@anuragpandey8165 2 жыл бұрын
Same. Striver is magical.
@surajmisal3898
@surajmisal3898 2 жыл бұрын
Same bro I also solved 3 approaches without watching.
@udaypratapsingh8923
@udaypratapsingh8923 2 жыл бұрын
bro what r you doing write now ? means professionally ?
@sagartaak4017
@sagartaak4017 2 жыл бұрын
@@udaypratapsingh8923YES
@sagartaak4017
@sagartaak4017 2 жыл бұрын
@@anuragpandey8165 YUP
@GauravThinks
@GauravThinks Жыл бұрын
For someone finding Recursive + memoised, tabulated, space optimised approaches: My flow of solving the dp is opposite to that of what Raj bhai do, (I prefer starting index from 0---> n-1) so accordingly, down below are my approaches: #include int helper(int ind, int capacity,vector &profit, vector &weight, int n, vector &memo){ if(ind>=n) return -1e9; if(capacity==0) return 0; if(memo[ind][capacity]!=-1) return memo[ind][capacity]; // take, nottake int take=0, nottake=0; if(weight[ind]
@jagannathan1014
@jagannathan1014 Жыл бұрын
best thing about him is , rather than teaching how to simply solve ,he teaches us how to think , which makes us solve on our own ! GOD level!
@tasneemayham974
@tasneemayham974 Жыл бұрын
STRIVER! I solved the whole problem in recursion, memoization, tabulation, Space optimization and then even the 1D Array ALL ALONEEE!! Thank youuuu! YOU ARE THE BEST TEACHER!! 🙌👏👏
@_Kunal_Pawar
@_Kunal_Pawar 11 ай бұрын
Understood! Since you've already explained these concepts so well in the previous problem, I was able to solve it on my own. Thanks, Striver! 💯
@mantrarajgotecha3055
@mantrarajgotecha3055 2 жыл бұрын
Whhoooaa striver, excellent concept. Without seeing the solution, I am able to solve it with all approaches, all credit goes to you sirji.
@sarthakragwan5248
@sarthakragwan5248 2 жыл бұрын
Even befor you explained the question just by name of topic i got the que what we gona do and i smiled like just 10 days ago i was suffering from DP and now i can predict what the que gonna be 😌Thanks Stiver Respect +++✌️
@GManiKarthik
@GManiKarthik 2 ай бұрын
Hey Striver, except the last approach of space optimization using 1-D Array, rest I have solved the problem in all the 3 approaches & corresponding time complexities. All credit goes to you man! Thanks a lot. You are the GOAT of DSA. #Understood #DP23 #Hatsoff #Striver
@nilimsankarbora5911
@nilimsankarbora5911 Жыл бұрын
Hey Striver, I solved the problem in all 3 approaches without watching the video. All credit goes to you, Thanks a lot. You are the best.❤❤❤❤❤
@shaisthatabassum-f1o
@shaisthatabassum-f1o 28 күн бұрын
did it all by myself till space optimization, u explained everything well from the starting, as always understood. BTW am binge watching this playlist
@thepleasantmoment2705
@thepleasantmoment2705 Жыл бұрын
Hey Striver, I solved the problem without watching the video. All credit goes to you, Thank you so much.
@SelvaArumugam-xq5mf
@SelvaArumugam-xq5mf Жыл бұрын
Hey Striver, I solved the problem in all 3 approaches without watching the video. All credit goes to you, Thanks a lot. You are the best.
@adityarai30
@adityarai30 Жыл бұрын
Hey striver, I have been watching your videos since very long and especially this playlist has helped me overcome the fear of dp.....thanks a lot🙏🙏♥♥
@amitkulkarni9682
@amitkulkarni9682 9 ай бұрын
Only KZbinr who will teach you in way so that you think on your own and solve it without watching his video. No Words !💯
@meetharsoda5152
@meetharsoda5152 8 ай бұрын
1-D Array Approach was amazing. Thank You
@lakshsinghania
@lakshsinghania 7 ай бұрын
why didnt we do from right to left ? the iteration
@SujalMahalaha
@SujalMahalaha 6 ай бұрын
@@lakshsinghania Because we need the current guy’s backward data and not previous guy’s
@Sachin-je7ue
@Sachin-je7ue Жыл бұрын
I followed this series from first videos and at this stage.I did this question in 11:44 min without watching this video. Thanks bro for your efforts to make such playlist.
@ankishkhandelwal1061
@ankishkhandelwal1061 2 жыл бұрын
i solved this problem in all approach recursion >>>>> memo>>>> tabulation >>>>> space optimization[ 2 * 1d array] >>>>>> space optimization[1d array] without watching the video.. thank you so much ... you are amazing teacher ..
@NalinTrivedi-b5o
@NalinTrivedi-b5o 2 ай бұрын
your way of teaching is just out of the world
@dipanshusharma9084
@dipanshusharma9084 2 жыл бұрын
understood, done the problem from recursion to tabulation with space optimization by myself..... very thankful for this dp playlist.
@himanshuagrawal8012
@himanshuagrawal8012 2 жыл бұрын
I Solved By my own till 2 array space optimization,..Thanks a lot for the awesome quality content #UNDERSTOOD
@imranimmu4714
@imranimmu4714 Жыл бұрын
Solved the problem without watching the video. Thank you for the knowledge you are providing.
@suhaanbhandary4009
@suhaanbhandary4009 2 жыл бұрын
From not solving to any problem using Tabulation to Solving at first go, thanks for In-depth DP video!!
@MindsetMastery550
@MindsetMastery550 19 күн бұрын
hey sir i have also solved this problem completely without watching this video and in one go thanks a lot for this masterpiece dp series .
@EliasEH89
@EliasEH89 Жыл бұрын
Best DP series in all KZbin.
@shivammaurya9630
@shivammaurya9630 Жыл бұрын
You actually made dp easy now I only need to think of recursion and that's it🌝
@surajmisal3898
@surajmisal3898 2 жыл бұрын
Following this series from first video and Solved this question without watching the video. (I would not have solved any problem in last month same date but now I can solve basic and medium level dp problem). Thanks to striver.
@thebestview8411
@thebestview8411 3 ай бұрын
Thank you Striver, I was able to solve the problem(all 3 approaches) with minor hints, thank you
@OnstreamGaming
@OnstreamGaming 2 ай бұрын
Understood and solved !!! From now I can say that only thing in DP is to write the recurrence --> and rest we can figure it by looking at recurrence--> also have some difficult when dealing with negative numbers in the Tabulation method bottom up.
@prathamlohia8496
@prathamlohia8496 24 күн бұрын
4/4 at first try without any errors. Thank you Striver.
@SYCOA12CHAITANYAASOLE
@SYCOA12CHAITANYAASOLE 5 ай бұрын
Understood !! hey striver i solved the problem on my own, feels amazing, keep going , keep growing !!
@KUMARSAURABH-s5i
@KUMARSAURABH-s5i 5 ай бұрын
Thanks, solved using all the 3 approach without watching this video. Great dp series
@KeigoEdits
@KeigoEdits 5 ай бұрын
If someone is wondering why we iterate in forward manner in inner loop in unbounded knapsack while 1-d array optimization, and in reverse order in bounded knapsack, just remember this rule of thumb For bounded knapsack problems (each item can only be used once), reverse iteration is important to avoid reusing the same item. For unbounded knapsack problems (items can be reused), forward iteration ensures you're considering the possibility of reusing the same item multiple times within the same loop
@prabhakaran5542
@prabhakaran5542 11 ай бұрын
Understood ❤
@DevashishJose
@DevashishJose Жыл бұрын
thank you so much striver, my understanding has improved so much watching these video. may god bless you.
@socify4410
@socify4410 Жыл бұрын
i done it my own although it was based on preveous problems but this shows you are getting ready for new preblems too.
@mriduljain6809
@mriduljain6809 2 жыл бұрын
Was able to solve all 4 approaches without seeing the video, although was very delighted to watch the space optimization. Thank you bhaiya for making dp so easy:)) "Understood"
@ShubhamKumar-fn5be
@ShubhamKumar-fn5be Жыл бұрын
understood but i did this before watching the video to test whether i am able to solve. You have made us think on our own Thanks Striver.😄😄
@cosmiccometyt
@cosmiccometyt 5 ай бұрын
Thank you so much striver, i solved the problem using all 3 approaches without watching the video. I didn't think that i had it in me to do it but hey, i did it. 😭😭
@rushirajparekh9079
@rushirajparekh9079 9 ай бұрын
Superb.. last level of space optimization!!
@princeshubham26
@princeshubham26 Жыл бұрын
Solved by myself all memoization, tabulation and space optimization done.😀😀
@somnathroy102
@somnathroy102 Жыл бұрын
I was able to do it and do no believe it myself. thank you so much.
@anshsaxena7297
@anshsaxena7297 6 ай бұрын
Thanks alot striver, I have completed the problem on my own. Thanks alot!
@UtkarshWasHereBeforeYou
@UtkarshWasHereBeforeYou 4 ай бұрын
3 days ago: DP is one of my weekest topics, i fear it to death. DP-1: OK, LET'S DO THIS. DP-15-17 I think I'm getting a hang of it. DP-20s Can DO IT MYSELF NOW.. bye, i'm going to understand all the remaining patterns ahead. and also, Understood.
@manishprajapati8544
@manishprajapati8544 2 жыл бұрын
hello striver solved this question in all approaches except the tabulation one got confused of base case but i was close to exactly what you have done in this video. that means i'm learning great thanks for this wonderfull playlist.
@sagartaak4017
@sagartaak4017 2 жыл бұрын
i get you bro u must not start your base case for loop from weight [0] to w+1 instead u start it from 0 to w+1; same happen here!!
@aliabbas-kj7lm
@aliabbas-kj7lm Жыл бұрын
was able to solve at one go. Well done Striver
@DivineVision201
@DivineVision201 2 жыл бұрын
bhaiya content bohot acha hai apka. i am really enjoying it. thanks for this
@koushande5679
@koushande5679 2 жыл бұрын
Solved before watching the video.. you have made dp easy for me :) Thank you
@shivkumar-og4ow
@shivkumar-og4ow 2 жыл бұрын
understood bhaiya! i solved this problem all three approch without watching this vedio.
@RohitKumar-dy2gc
@RohitKumar-dy2gc Жыл бұрын
1d array approach is super wonderful 😊😊😊😊
@shaktiprasannasahoo7845
@shaktiprasannasahoo7845 3 жыл бұрын
Understood😃 and please make some videos where we can't use 2D Vector ,i.e. we need hashmaps to store them becoz I'm facing problem on that kind of qs. Your contents are the best👌👌. Thank you
@anmol3749
@anmol3749 Ай бұрын
Understood Thank you striver⚡
@dennyage4791
@dennyage4791 3 жыл бұрын
I done it by my self , all thanks goes to striver 😁😁
@ketansarode17
@ketansarode17 2 жыл бұрын
striver....u are like a gem for us🥺☺
@komalgoel8308
@komalgoel8308 8 ай бұрын
understood☺
@aruna5869
@aruna5869 11 ай бұрын
understood :)❤
@ranasauravsingh
@ranasauravsingh 2 жыл бұрын
UNDERSTOOD... ! Thanks striver for the video... :)
@ntgrn-pr5yx
@ntgrn-pr5yx 3 ай бұрын
UNDERSTOOD , THANK YOU STRIVER
@MukeshKumar-cc3uh
@MukeshKumar-cc3uh 11 ай бұрын
Awesome content in this series! Thank you and Understood ♥
@pranaypatadiya
@pranaypatadiya 2 жыл бұрын
Smartest thing on the planet ❣
@Enigm.1.
@Enigm.1. 4 ай бұрын
understood
@morganyu3391
@morganyu3391 2 жыл бұрын
This was the video which solidified my understanding in DP from all the concepts learnt in the previous videos. thank you so much Striver Bhaiya! Understood not only this video but the previous videos clearly!
@omkarkawatgi
@omkarkawatgi 2 жыл бұрын
Base case i
@Sara-ed3jq
@Sara-ed3jq Жыл бұрын
I got till memoization but made small mistake in tabulation, thankyou for teaching so well !
@lohitaksha244
@lohitaksha244 2 жыл бұрын
Understood, did all and even space optimization to 1 1d array before watching video
@ritikshandilya7075
@ritikshandilya7075 7 ай бұрын
Thankyou for great explanation striver
@ratinderpalsingh5909
@ratinderpalsingh5909 2 жыл бұрын
Understood, sir. Thank you very much.
@cypher7536
@cypher7536 2 жыл бұрын
Bhaiya recursion to space optimisation khud likha pura ❤️❤️❤️
@shreyasnagabhushan4918
@shreyasnagabhushan4918 2 жыл бұрын
understood , amazing explanation, sets clearly in the mind
@sachinchoudhary4142
@sachinchoudhary4142 10 ай бұрын
I am not understanding why we are not traversing for capacity from back for 1D space optimization as for cur index we need prev index values and cur array prev values so why not from back traverse
@chanchalroy3417
@chanchalroy3417 Жыл бұрын
Understood! Just wow 😲
@parthsalat
@parthsalat 2 жыл бұрын
Continue from 18:00
@arvindjaiswal8013
@arvindjaiswal8013 7 ай бұрын
Awesome explanation...
@chitranshjain5075
@chitranshjain5075 2 жыл бұрын
Understood. Kudos to you for the amazing job! Can you make a playlist on Array problems too?
@abdalla4425
@abdalla4425 Жыл бұрын
UNDERSTOOD BABY!
@lakshaysharma6550
@lakshaysharma6550 2 жыл бұрын
UNDERSTOOD!!!🔥🔥🔥🔥🔥🔥
@kathanvakharia
@kathanvakharia Жыл бұрын
Understood...Completed (23/56)
@shubh625
@shubh625 6 ай бұрын
understood and did till space optimization on my own missed
@sameersahu4569
@sameersahu4569 2 жыл бұрын
Understood Striver!!!Thank you for the amazing content
@abhirupbasu3386
@abhirupbasu3386 2 жыл бұрын
the 1-D array part was so good. UNderstood.
@vineetsingh4707
@vineetsingh4707 Жыл бұрын
Understood
@kanchandubeyvlog
@kanchandubeyvlog 3 жыл бұрын
Amazing bahot Achha padhate ho ❤️❤️
@sahilarya9510
@sahilarya9510 3 жыл бұрын
aap kyuun padh rhi ho didi
@Kunaaaal17
@Kunaaaal17 Жыл бұрын
UNDERSTOOD!!!! AND LOVED IT!!
@johnsimon8158
@johnsimon8158 3 ай бұрын
thanks for this awesome content
@santoshb7776
@santoshb7776 Жыл бұрын
Understood sir !🙏🙏
@ganeshkamath89
@ganeshkamath89 2 жыл бұрын
Thanks Striver. Understood. Learnt a lot.
@adityasaxena6971
@adityasaxena6971 Жыл бұрын
Thanks a Lot Striver🤩
@TanviPoddar-f1k
@TanviPoddar-f1k 8 ай бұрын
Shouldn't we traverse the prev array from right to left as the current value is dependent on previous values which keep changing if we traverse from left to right in the single array approach?? You did that in the 0-1 knapsack problem.
@SouravKumar-um7pr
@SouravKumar-um7pr 8 ай бұрын
I am thinking the same
@saumilaggarwal5233
@saumilaggarwal5233 Жыл бұрын
thnx, was able to do this by myself
@gangsta_coder_12
@gangsta_coder_12 2 жыл бұрын
Understood 💯💯💯
@kumarpurushottam632
@kumarpurushottam632 2 жыл бұрын
Understood Thanks You Striver 😍
@0xrod
@0xrod 3 жыл бұрын
Was waiting for this 😁
@shubhamtripathidev
@shubhamtripathidev 2 жыл бұрын
buying vegetables is the variation of ninjas training on gfg
@cinime
@cinime 2 жыл бұрын
Understood!! Thank you very very VERY MUCH!!!
@iamnoob7593
@iamnoob7593 Жыл бұрын
understood , Thanks striver
@vatsalvasoya5243
@vatsalvasoya5243 2 жыл бұрын
Very well explained!!
@jeelanibasha3984
@jeelanibasha3984 6 ай бұрын
Instead of pick to be zero cant we keep int_ min or -1e9 as we were finding the max element
@sujitmourya8481
@sujitmourya8481 Жыл бұрын
understood very well
@lakshsinghania
@lakshsinghania Жыл бұрын
hey striver, at 13:27 why didnt we write this condition statement in the base case if(wt[0]
@Echo-942
@Echo-942 Жыл бұрын
Look We can do it like this as well if(ind == 0){ if(weight[0]
@Echo-942
@Echo-942 Жыл бұрын
Observe that Even if you won't write the condition if(weight[0] maxWeight then (maxWeight/weight[0]) is always going to be 0. Hence this case is automatically handled ! Hope this helps.
@dibyanikshetry3775
@dibyanikshetry3775 Жыл бұрын
but why adding that statement is giving wrong answer , it should pass all the test cases no ?i am trying to figure this out for so long😭😭😭😭@@Echo-942
@lakshsinghania
@lakshsinghania 7 ай бұрын
@@Echo-942 aite got it! ik its 1 yr later xd but got it that time. just revising the stuffs
@VikashYadav-px8ei
@VikashYadav-px8ei Жыл бұрын
Understood 🎉
@sampreethmiriyala1086
@sampreethmiriyala1086 2 жыл бұрын
UNDERSTOOD.... Thank you striver
DP 24. Rod Cutting Problem | 1D Array Space Optimised Approach
22:54
take U forward
Рет қаралды 210 М.
So Cute 🥰 who is better?
00:15
dednahype
Рет қаралды 19 МЛН
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
5 Secrets to Stop Stuttering & Speak More Clearly!
12:44
Vinh Giang
Рет қаралды 143 М.
Writing Code That Runs FAST on a GPU
15:32
Low Level
Рет қаралды 583 М.
Как наука победила религию
17:02
The 0/1 Knapsack Problem (Demystifying Dynamic Programming)
20:30
Back To Back SWE
Рет қаралды 212 М.
DP 20. Minimum Coins | DP on Subsequences | Infinite Supplies Pattern
34:15
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 857 М.