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

แชร์
ฝัง
  • เผยแพร่เมื่อ 5 ก.ย. 2024
  • 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...

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

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

    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 ปีที่แล้ว +7

      Same. Striver is magical.

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

      Same bro I also solved 3 approaches without watching.

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

      bro what r you doing write now ? means professionally ?

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

      @@udaypratapsingh8923YES

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

      @@anuragpandey8165 YUP

  • @tasneemayham974
    @tasneemayham974 11 หลายเดือนก่อน +17

    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!!
    🙌👏👏

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

    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!

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

    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 +++✌️

  • @GauravThinks
    @GauravThinks 7 หลายเดือนก่อน +4

    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]

  • @meetharsoda5152
    @meetharsoda5152 3 หลายเดือนก่อน +6

    1-D Array Approach was amazing. Thank You

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

      why didnt we do from right to left ? the iteration

    • @user-vk8db3ph2v
      @user-vk8db3ph2v หลายเดือนก่อน +1

      @@lakshsinghania Because we need the current guy’s backward data and not previous guy’s

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

    Whhoooaa striver, excellent concept.
    Without seeing the solution, I am able to solve it with all approaches, all credit goes to you sirji.

  • @SelvaArumugam-xq5mf
    @SelvaArumugam-xq5mf 7 หลายเดือนก่อน

    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.

  • @_Kunal_Pawar
    @_Kunal_Pawar 6 หลายเดือนก่อน +1

    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! 💯

  • @nilimsankarbora5911
    @nilimsankarbora5911 8 หลายเดือนก่อน +1

    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.❤❤❤❤❤

  • @thepleasantmoment2705
    @thepleasantmoment2705 7 หลายเดือนก่อน +1

    Hey Striver, I solved the problem without watching the video. All credit goes to you, Thank you so much.

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

    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🙏🙏♥♥

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

    I Solved By my own till 2 array space optimization,..Thanks a lot for the awesome quality content #UNDERSTOOD

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

    understood, done the problem from recursion to tabulation with space optimization by myself..... very thankful for this dp playlist.

  • @shivammaurya9630
    @shivammaurya9630 8 หลายเดือนก่อน +2

    You actually made dp easy now I only need to think of recursion and that's it🌝

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

    Only TH-camr who will teach you in way so that you think on your own and solve it without watching his video. No Words !💯

  • @user-kl3qv1sc8k
    @user-kl3qv1sc8k 15 วันที่ผ่านมา

    Thanks, solved using all the 3 approach without watching this video.
    Great dp series

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

    From not solving to any problem using Tabulation to Solving at first go, thanks for In-depth DP video!!

  • @user-is6ky7pp2n
    @user-is6ky7pp2n 18 วันที่ผ่านมา

    Understood !! hey striver i solved the problem on my own, feels amazing, keep going , keep growing !!

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

    Solved the problem without watching the video.
    Thank you for the knowledge you are providing.

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

    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 ..

  • @Sachin-je7ue
    @Sachin-je7ue 7 หลายเดือนก่อน

    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.

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

    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

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

    Solved by myself all memoization, tabulation and space optimization done.😀😀

  • @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.

  • @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.

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

    Best DP series in all TH-cam.

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

    Thanks alot striver, I have completed the problem on my own. Thanks alot!

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

    I done it by my self , all thanks goes to striver 😁😁

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

    Understood, sir. Thank you very much.

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

    Understood, did all and even space optimization to 1 1d array before watching video

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

    thank you so much striver, my understanding has improved so much watching these video. may god bless you.

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

    Superb.. last level of space optimization!!

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

    understood and did till space optimization on my own
    missed

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

    UNDERSTOOD... !
    Thanks striver for the video... :)

  • @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 ปีที่แล้ว

      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!!

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

    I was able to do it and do no believe it myself. thank you so much.

  • @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.😄😄

  • @sachinchoudhary4142
    @sachinchoudhary4142 5 หลายเดือนก่อน +3

    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

  • @Sara-ed3jq
    @Sara-ed3jq ปีที่แล้ว

    I got till memoization but made small mistake in tabulation, thankyou for teaching so well !

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

    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"

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

    Understood. Kudos to you for the amazing job! Can you make a playlist on Array problems too?

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

    Thankyou for great explanation striver

  • @aliabbas-kj7lm
    @aliabbas-kj7lm ปีที่แล้ว

    was able to solve at one go.
    Well done Striver

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

    Solved before watching the video.. you have made dp easy for me :) Thank you

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

    Base case i

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

    Can anyone explain why left to right (W=0 to maxWeight) does not work in 01 knapsack, but it does work in unbounded knapsack. I am very confused they look similar to me. Please help!

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

    Understood...Completed (23/56)

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

    bhaiya content bohot acha hai apka. i am really enjoying it. thanks for this

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

    Why the forwoard iteration of wieght for using 1-d array not causing any problem?like dp 19

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

      Because we need the current guy’s backward data and not previous guy’s

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

      @@takeUforward in 19 th also we wanted curr guys backward na so why error there

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

      @@sushant8686 in 19 , we were no in the same index after taking a particular element , consider the following statement of taking a particular element of dp 19 and this video :-
      dp 19:
      take = value[ind]+help(ind-1,w-weight[ind],weight,value,dp);
      dp 23:
      take = profit[ind]+help(ind,w-weight[ind],profit,weight,dp);
      in case of dp 19 , we are going to ind-1 , and for that , in our tabulation code , we will use prev array , in case of dp 23 we are in same index , and in our tabulation code , we will use curr array , if we are using curr , we do not need to worry about prev[w-weight[ind]], that is why forward iteration will work here .

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

      @@abhimanyusingh6445 thanks bhai you have cleared my doubt🙏🙏

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

    striver....u are like a gem for us🥺☺

  • @shivkumar-og4ow
    @shivkumar-og4ow ปีที่แล้ว

    understood bhaiya! i solved this problem all three approch without watching this vedio.

  • @RohitKumar-dy2gc
    @RohitKumar-dy2gc 10 หลายเดือนก่อน

    1d array approach is super wonderful 😊😊😊😊

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

    understood , amazing explanation, sets clearly in the mind

  • @MukeshKumar-cc3uh
    @MukeshKumar-cc3uh 6 หลายเดือนก่อน

    Awesome content in this series! Thank you and Understood ♥

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

    Awesome explanation...

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

    hey striver finally i am being to solve this without watching the solutions a;ll thanks to you man ❤❤ and a Big "Understood".

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

    Understood!! Thank you very very VERY MUCH!!!

  • @prabhakaran5542
    @prabhakaran5542 5 หลายเดือนก่อน +1

    Understood ❤

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

    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!

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

    Understood! Just wow 😲

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

    Bhaiya recursion to space optimisation khud likha pura ❤️❤️❤️

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

    Striver, we need problem where we can't use 2D grid , we have to use hashmaps for memo...

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

      how are those different? maybe we should be able to solve them using maps to store. Or am i missing something?

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

      @@mikelan9854 I guess the approach will be same just converting the 2d variables in form of string and storing it

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

      @@thinkingmad1685 2d array is efficient as using map might give tle some times

  • @shubhamkumar-hx1fb
    @shubhamkumar-hx1fb 6 หลายเดือนก่อน

    us...and also submitted the question in all the approaches by myself

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

    Thanks Striver. Understood. Learnt a lot.

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

    Smartest thing on the planet ❣

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

    the 1-D array part was so good.
    UNderstood.

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

    UNDERSTOOD....
    Thank you striver

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

    Understood Striver!!!Thank you for the amazing content

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

    thnx, was able to do this by myself

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

    UNDERSTOOD BABY!

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

    Continue from 18:00

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

    solved it by myself. Thank you striver.

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

    understood , Thanks striver

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

    understood ,thanks alot

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

    Thank U striver.

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

    Understood,able to solve by myself till 2 array space optimization

  • @TON-108
    @TON-108 11 หลายเดือนก่อน

    Understood!!
    Thanks!

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

    Understood Sir, Thank you very much

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

    Understood sir !🙏🙏

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

    Bhaiya ,why are we not writing the base case for weight parameter here ? how will the Take call terminate as the index is not decreasing , the weight is ,but there is no base case for weight ?

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

      we don't have base case for that but we do have restriction for recursion call , that is when bag weight is less than the weight of item we will stop taking items and for that particular call take will be zero
      Make recursion tree to understand more....

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

      thanks for asking this . I also have same doubt

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

    thank you very much striver i have solved this sum by my own

  • @komalgoel8308
    @komalgoel8308 3 หลายเดือนก่อน +1

    understood☺

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

    understood, but I solved this problem myself without seeing the solution upto 2 array space optimization. Needed the video to realize further optimization to a single array.

  • @KunalTambe-oy6lb
    @KunalTambe-oy6lb ปีที่แล้ว

    UNDERSTOOD!!!!
    AND LOVED IT!!

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

    Thanks striver, was able to do it in all four ways by myself after sincerely following your playlist. ❤

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

    Here why are we using overidden values from the left ? unlike in knapsack problem where we went from the right

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

    Question: How does the tabulation cover the case of picking multiple elements?

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

      bro u use dp[i][t-weight[i]] in pick case
      and in not pick use dp[i-1][t];
      and if you want to know working watch old videos in which striver sir explain it deeply
      or dry run for small values you get it easily and never forget then if you DIY

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

    understood very well

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

    Very well explained!!

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

    Amazing bahot Achha padhate ho ❤️❤️

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

      aap kyuun padh rhi ho didi

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

    Understood Thanks You Striver 😍

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

    Understood bhaiyya!

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

    Understood, thanks!

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

    buying vegetables is the variation of ninjas training on gfg

  • @aruna5869
    @aruna5869 6 หลายเดือนก่อน +1

    understood :)❤

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

    hey striver, at 13:27 why didnt we write this condition statement in the base case
    if(wt[0]

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

      Look We can do it like this as well
      if(ind == 0){
      if(weight[0]

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

      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 10 หลายเดือนก่อน

      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😭😭😭😭@@ObitoXuchiha942

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

      @@ObitoXuchiha942 aite got it! ik its 1 yr later xd but got it that time. just revising the stuffs

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

    Thanks a Lot Striver🤩

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

    Understoood sir!!

  • @VikashYadav-px8ei
    @VikashYadav-px8ei ปีที่แล้ว +1

    Understood 🎉