subset sum problem dynamic programming | backtracking sum of subsets

This is a video lecture which explains subset sum problem solving using both backtracking and dynamic programming methods. This explanation is a little long but once you watch it, you won't ever regret about having watched such a long video. Backtracking takes exponential time to solve the subset sum problem therefore, we solve using it dynamic programming. I am sure you will love the explanation :)
CODE LINK: drive.google.com/open?id=1qs4...
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 :)

Пікірлер: 212

  • @VS-cy8oy
    @VS-cy8oy4 жыл бұрын

    Thank you very much for this explanation, i went over many videos over youtube but didn't get any intuition for this problem, but the way you distinguished both approaches made me understand this problem very well.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @alessandrocamillo4939
    @alessandrocamillo49393 жыл бұрын

    I really love this video. It explain the problem and gives two solutions. With the first solution it builds the required intuition to understand that the problem show a dynamic programming pattern and use it to build up a bottom-up solution. Thank you very much

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @aniketdubey7363
    @aniketdubey73633 жыл бұрын

    the best of the explaination i had seen so far

  • @mayankchauhan6680
    @mayankchauhan66803 жыл бұрын

    Thanks alot Algo Buddy. Words are not enough to praise you but you are the best teacher, its like a magic that you teach even hardest of hard concept as if it was always easy. You are going to rock algo learning world someday for sure.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks for your motivation bro :)

  • @parthshah6343
    @parthshah63434 жыл бұрын

    One of the best explanations of subset sum problem!

  • @himalayagupta7744
    @himalayagupta77444 жыл бұрын

    explained clearly , leaves no doubt in my mind , thank you sir.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @abhimanyupagade4289
    @abhimanyupagade42893 жыл бұрын

    Literally you are gem Thanks for your quality teaching keep it up

  • @jhilikkundu3158
    @jhilikkundu31583 жыл бұрын

    At first I want to thank you. I was trying to understand how the matrix is fullfilling the XOR logic. When I was trying to dry run the code I found, it was not being match with the logic. I have searched and seen a lot of subset sum problem video, even repeat the knapsack video also. Then suddenly at this time of night I find a channel with less subs and even lesser view. I started with very less expectation but sir forgive me for my previous thoughts. I finally understood what is happening and I found by myself that I have a error in my code. When I am able to find the error, I understood the logic. I feel relaxed. I will share this channel, and will watch more dp video if u have.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks :)

  • @akhilkhubchandani2632
    @akhilkhubchandani26324 жыл бұрын

    The best explanation!. Made this problem seem so easy . Thanks a lot !

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @Nickel80
    @Nickel803 жыл бұрын

    Gave an applaud to this video and another video of yours. Keep up the good work :)

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks for supporting us ❤️

  • @anandakrishnan2685
    @anandakrishnan26852 жыл бұрын

    Really good video. I want to point out something @tech_dose that in your code the order of initializing the array with true and false should be swapped(the first row and first column) since if we initialize the column first it will get overwritten.

  • @dancojocaru7217
    @dancojocaru72172 жыл бұрын

    Very good and clear explanation! Thank you!

  • @aayush5474
    @aayush54744 жыл бұрын

    bro your explanation is the best! Other videos on youtube don't explain how the table is forming and the sub problems but you explain that.Thanks a lot!

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @aayush5474

    @aayush5474

    4 жыл бұрын

    @@techdose4u bro can you make a video on subset sum divisible by m problem? It's a variant of this problem but harder and i can't understand the approach

  • @namisha6883
    @namisha68833 жыл бұрын

    Amazing content. Clearly visible that you are putting a lot of hard work.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks

  • @CodeSuccessChronicle
    @CodeSuccessChronicle3 жыл бұрын

    If anyone wants to know how backtracking actually works this is the recommended video. Bro the way you did backtrack till last possibility is amazing. Thank you so much 🙏🏻🥰

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    Same feel. I understood backtracking properly with this video. I didn't know that I was doing backtracking when I was coding that method in the first place 😆

  • @iampatelajeet
    @iampatelajeet2 жыл бұрын

    Amazing explanation bro, can't go without liking.

  • @sandeepnallala48
    @sandeepnallala483 жыл бұрын

    one day sir you will become the biggest competitor for many other ppl teaching DSA sir. thanks a lot sir ..... : )

  • @taivinh1986
    @taivinh19863 жыл бұрын

    I love this channel, thanks for it, i see i have ameliorated a lot, i will always support it

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks 😊

  • @Stuff395
    @Stuff395 Жыл бұрын

    Great job, explaining this! 🎉

  • @ShivamSingh-me1nb
    @ShivamSingh-me1nb3 жыл бұрын

    Great explanation, i have never seen anyone explain that much in you tube

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks

  • @ganeshkamath89
    @ganeshkamath892 жыл бұрын

    At first I thought why this is needed because I can iterate all elements in a nested for loop to find the sum. Then I changed {2, 2, 3} and sum {7} instead of 5, by running the attached code. Then it made lot of sense. Instead of needing to iterate with 3 iterator variables over all elements, this method shows a simple technique to get the subset. Now I am convinced. Thanks a lot. Are you converting a n dimensional problem to a 2 dimentional problem with Knapsack?

  • @AkashKumar-ym4gu
    @AkashKumar-ym4gu3 жыл бұрын

    This Channel Needs To Be Popular.. Absolutely Great Stuff.. ❤❤

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks :)

  • @arunimadas3183
    @arunimadas31833 жыл бұрын

    Thanks a lot for this.❤️. I finally understood it 😭❤️ . Keep up the good work. :')

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome 😊

  • @ritiksolanki6267

    @ritiksolanki6267

    3 жыл бұрын

    Rona kya isme🙄😂😂

  • @spetsnaz_2

    @spetsnaz_2

    3 жыл бұрын

    @@ritiksolanki6267 khushi k aansu

  • @debanjanghosh5698
    @debanjanghosh56984 жыл бұрын

    I was looking for such videos. Really helpful 👌👍

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks :)

  • @chaunguyen8202
    @chaunguyen82022 жыл бұрын

    Great video! :) Liked and subscribed!

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    Thanks 😊

  • @vdengineering2666
    @vdengineering2666 Жыл бұрын

    super super super amazing thx!!

  • @jatinthakwani5370
    @jatinthakwani53704 жыл бұрын

    God bless you! I was looking for this type of explanation. Please start some online course on which you will cover these topics in-depth.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Yep. I will do it at some point of time.

  • @tarungopal3065
    @tarungopal30654 жыл бұрын

    Superb and clear Explanation..You are very great at making these videos for free...

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks

  • @adityaojha2701
    @adityaojha27013 жыл бұрын

    Thanks a lot sir. Now I clearly understood.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @ashishkulkarni7674
    @ashishkulkarni76742 жыл бұрын

    Hi sir, you teach everything very cleanly...please keep teaching us😊

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    For sure ❤️

  • @aditisharma2552
    @aditisharma25523 жыл бұрын

    Very well explained! You definitely need more likes..

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks for liking ❤️

  • @dayanandraut5660
    @dayanandraut56603 жыл бұрын

    understanding recursive intuition is easy, and writing that into dp was tough for me. but now if i can come up with recursive soln, i can easily write that into dp. Thanks to @Tech Dose

  • @amarnaath5673
    @amarnaath56734 жыл бұрын

    IF YOU START AN ONLINE COURSE I LL BE THE FIRST ONE TO REGISTER

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks bro:)

  • @maverickchinmaydas
    @maverickchinmaydas4 жыл бұрын

    @TECH DOSE - Nice video , well explained and I cleared doubt on how to track down the nodes but can you please tell me if I want to see what all subset elements are added to get the sum then how to track back from last node that is 3*5 = T

  • @tonyriddle7646
    @tonyriddle76463 жыл бұрын

    most underated channel

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    😅

  • @dhruvgoel25
    @dhruvgoel254 жыл бұрын

    Very well explained 👍 thank you sir..keep making such videos

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek93983 жыл бұрын

    clean and crisp please make a video on time complexity ?how to find it ur explanations are great

  • @nallasivakrishna5693
    @nallasivakrishna56934 жыл бұрын

    what are the changes made in the code from naive approach I did not get you.. and Sir please explain how to print in backtracking approach I am unable to get it.

  • @chainsinghpawar9138
    @chainsinghpawar91382 жыл бұрын

    Can we find max size of subarray having a sum k say 5 by this technique

  • @warrenbuffet2511
    @warrenbuffet25113 жыл бұрын

    You're a BOSSSS!

  • @Mandeepsingh-jo5cf
    @Mandeepsingh-jo5cf3 жыл бұрын

    Thanks for this magical explanation.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @neghatnazir1668
    @neghatnazir16683 жыл бұрын

    thanks a lot, i understood the concept behind filling this table ,one syggestion it could b better explained using recurssion tree that includes sub problems.

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Okay sure

  • @christopherbeatty8836
    @christopherbeatty88363 жыл бұрын

    Great video, thank you!

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome

  • @ravikiranbaisani2145
    @ravikiranbaisani21453 жыл бұрын

    Appreciate such a clean explanation

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks

  • @sugatasaha4423
    @sugatasaha44234 жыл бұрын

    great explanation... Thank you, sir.

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Welcome :)

  • @richardzhu2678
    @richardzhu26782 жыл бұрын

    Thank you so much

  • @soumeshnayak4546
    @soumeshnayak45462 жыл бұрын

    really best lecture perfect!!..

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    Thanks 😊

  • @abhishekkumargupta3043
    @abhishekkumargupta30434 жыл бұрын

    This is some nice stuff explained superbly!

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks

  • @niklas9562
    @niklas95624 жыл бұрын

    Very nice explanation in "Abob" (above) Video !

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    :)

  • @snehabaser3155
    @snehabaser31553 жыл бұрын

    Next level Explanation ✨

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks :)

  • @mirakabra2334
    @mirakabra23344 жыл бұрын

    Very nicely explained!

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks :)

  • @chrisogonas
    @chrisogonas3 жыл бұрын

    Well illustrated. Thanks

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @chakreshsingh
    @chakreshsingh2 жыл бұрын

    How will the solution change, is the set is allowed to have negative numbers..

  • @ameynaik2743
    @ameynaik27433 жыл бұрын

    Great video! The space complexity for dp is O(sum*size(set)) for your method which is bottom-up. But I guess we can perform dp top bottom approach, the Space complexity can be reduced to O(sum+1). Is that correct?

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    You can just maintain a row to do that

  • @souvikghosh1285
    @souvikghosh12854 жыл бұрын

    How can I print the Subest using dynamic programming?

  • @aakashsaini351
    @aakashsaini3514 жыл бұрын

    crystal clear explanation...

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks :)

  • @BaljeetSingh-bx8yj
    @BaljeetSingh-bx8yj3 жыл бұрын

    Great explanation!!

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks bhai :)

  • @anubhavsaha6225
    @anubhavsaha62254 жыл бұрын

    Sir any way to print the subsets using dynamic programming?..

  • @durjaarai7737
    @durjaarai77373 жыл бұрын

    At 2:51, is it required to search the 2nd option if the 1st returns true? Also, I wanted to thank you so much for the content. Solving this by hand and following along, helped me understand this concept.

  • @vinothrajg8576
    @vinothrajg85763 жыл бұрын

    Great ☺️ Thanks for the video

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @onestopplacement4917
    @onestopplacement49173 жыл бұрын

    Can u plz say which app is using for white board sir

  • @gauri360
    @gauri3602 жыл бұрын

    Very well explained

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    Thanks

  • @philipjames9194
    @philipjames91942 жыл бұрын

    how can you use this on lc 32 combination sum?

  • @saravanan925
    @saravanan9253 жыл бұрын

    Hi Tech Dose, the only request I am putting here is, Can you elaborate how the recursive formula came in every dynamic programming videos? Because after seeing your recursive formula only I am able to understand the logic, If you do consider that also, it would be more helpful. Thanks in advance. And one more, the explanation was awesome!!!

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks. I will try to derive the recursive formula from now on.

  • @saravanan925

    @saravanan925

    3 жыл бұрын

    Thank you brother

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    👍

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    This is a good requirement. I have first listened to the explanation, proceeded to write Recursive code first, and then wrote the DP. But in essence from interview point of view, it is better to be able to work with bottom up tabulation approach on the fly rather than going through recursion. Here the detailed explanation for filling the table, makes it intuitive enough to stand on its own.

  • @i.vigneshdavid1698
    @i.vigneshdavid16984 жыл бұрын

    can you tell me how to print elements of subset

  • @namanvijay3514
    @namanvijay35143 жыл бұрын

    crystal clear sir, 🙌🙌👏

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks :)

  • @vikaspatel-fi8dl
    @vikaspatel-fi8dl Жыл бұрын

    how to find which element is added to make SUM??

  • @niksgupta36
    @niksgupta362 жыл бұрын

    Would have been great if you explained memoization method before DP method. Good content btw! Thanks!

  • @techdose4u

    @techdose4u

    2 жыл бұрын

    👍🏼

  • @sindo1913
    @sindo19133 жыл бұрын

    THANK YOU!!

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome

  • @akshayagrawal2222
    @akshayagrawal22222 жыл бұрын

    Nice explaination but how can you implement tabulation solution directly from the recursive solution best way to learn dp is -> 1. find recursive solution, 2. implement memoized version of DP solution from recursive, 3. then at last we can move to tabulation approach

  • @physicsbyneha4210
    @physicsbyneha42103 жыл бұрын

    but what if i want to find all the subsets from a set, which gives a sum equal to a given value? (using DP, as it just tells me if its possible to get a subset or not i.e. true or false)

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    You would need to iterate this table to find all the "T" cells and print arr[i-1] of those cells.

  • @raulherbert
    @raulherbert4 жыл бұрын

    great video!

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    Thanks :)

  • @labib28
    @labib283 жыл бұрын

    wow thats great job

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks

  • @gauravbhisikar6381
    @gauravbhisikar63813 жыл бұрын

    thankkkkuuuu so much sir

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome :)

  • @debarunkumer2019
    @debarunkumer20192 жыл бұрын

    How to display the subsets that sum to the given value?

  • @bmuralikrishna8054
    @bmuralikrishna80544 жыл бұрын

    Thanks for the clear explanation. Please make some videos on bitmasking. There are very few available in youtube about bitmasking. Could you please let me know whether this problem can be solved using bit masking?

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    I will let you know once i try.

  • @bmuralikrishna8054

    @bmuralikrishna8054

    4 жыл бұрын

    @@techdose4u thank you for the reply. with the dynamic programming approach, Can we find the total no of subsets that will form the given sum?

  • @pranavrajeshmadhani6260
    @pranavrajeshmadhani62603 жыл бұрын

    Can you please explain why we are considering 1 row above? that logic I am not clear with

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    I will show this in one DP problem soon.

  • @vishnugovindan8550
    @vishnugovindan85503 жыл бұрын

    In the DP approach, how would we print the subset as well if we wanted to?

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    Simple. Whenever the cell is true, you will just need to print arr[i-1].

  • @rajkumarnagarajan2225
    @rajkumarnagarajan22253 жыл бұрын

    03:05 In the second condition, we are taking the value of 3 and computing 5-3 = 2, but why its sum - set[n-1] when set[n] is the current element.

  • @sasikumarvm5172

    @sasikumarvm5172

    3 жыл бұрын

    Here N is length of an array, we need to acess last element of an array, so n-1 will give acess to the last element

  • @mohdhasnain3812
    @mohdhasnain38123 жыл бұрын

    Bro i can't tell i was finding this from last 2 days...... you are an angel 🔥 Please tell me can we initialise the 1st row and column within the nested for loop in which we are checking all conditions

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    I have done in the same way. I am very lazy. So decided not to go for seperate initialization, but just kept if(i==0) d[i][j]=false else if (j==0) d[i][j]=true. I think the only disadvantage of doing it is that each single time when the decision needs to be taken, we will check for i==0 and j==0 for all elements, which can be avoided if we initialize them separately. I think this is the reason maybe to initialize it separately first.

  • @shuchitam3868
    @shuchitam38683 жыл бұрын

    I still cannot understand when do we need to have dp[n+1][target+1]? how have decided the range?

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    We don't use 0th row and column. So we take 1 extra size

  • @sazidimtiaz831
    @sazidimtiaz8313 жыл бұрын

    thanks 🙂

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Welcome

  • @bestsaurabh
    @bestsaurabh3 жыл бұрын

    If number of elements are high and the value are also high, (arr= [23423343, 33427262,62829927] ] ) do we have any other approach apart from exponential complexity?

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Recursion is exponential in No of elements and DP is exponential in Target SUM. If one is very large as compared to the other then you can apply the alternate methods.But, if both are large, maybe you can get idea from here: stackoverflow.com/questions/18432759/subset-sum-for-large-sums

  • @HariKrishnan-ff4hf
    @HariKrishnan-ff4hf4 жыл бұрын

    sir,By the way how to print those subsets in backtracking..kindly help sir

  • @techdose4u

    @techdose4u

    4 жыл бұрын

    In backtracking method, as soon as as you get your SUM = 0 then keep a return flag , make it true and when you return back to parent node then you will get your flag set and so you will understand that current node lies in the path of finding the subset. So whatever choice you made (you chose or you left the current node), you will stick to it. If you had not included the current node to find sum, then final set will exclude that element. This is the process for backtracking method.

  • @atharvamalhar7101
    @atharvamalhar71013 жыл бұрын

    Just wanted to ask is this series enough for placement preparation of dp questions?

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Follow my DP playlist Newbie to Expert. If you do that then you have covered the required placement topics. Now just need to keep on practice while doing other problems.

  • @akankshasharma148
    @akankshasharma1483 жыл бұрын

    Great explanation sir!! Please also create a video on Sudoku solver🙏

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Sure :)

  • @akankshasharma148

    @akankshasharma148

    3 жыл бұрын

    @@techdose4u Thanku🙏

  • @shaikzuhair8537
    @shaikzuhair85373 жыл бұрын

    Good explained

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Thanks

  • @srimakarmakar4498
    @srimakarmakar44983 жыл бұрын

    Bhaiya if the sum is very large , say like 10^8 or 9 then how can we solve it ???? 🤔🤔🤔🤔🤔

  • @v.sreesairam9488
    @v.sreesairam94883 жыл бұрын

    understood :)

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Nice :)

  • @MagicalCreationAviCreation
    @MagicalCreationAviCreation3 жыл бұрын

    sir did u make video on how to find all the possible subset of sum ? if u made then please comment that video link,Thank you

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    No I didn't. I think you are asking about bruteforce technique right?

  • @PhoenixRisingFromAshes471
    @PhoenixRisingFromAshes4713 жыл бұрын

    sir can i solve it using hashmap?

  • @mindandmachine01
    @mindandmachine01Ай бұрын

    Di they fixed error 12?

  • @michaelchan6144
    @michaelchan61443 жыл бұрын

    Hi there, this is your code describing how to determine if True or False for each cell in matrix subset[i][j] = subset[ i - 1][ j ] | | subset[i - 1][j - set[i - 1]]; The second half after the OR operator represents what happens when we SELECT the I'th Element. My question is why is it j - set[i - 1] and NOT j - set[ i ]. Shouldn't we minus the current sum(j) by the current 'weight' (set[i]) of the i'the element and see if the first i - 1 elements can sum up to it?

  • @chaunguyen8202

    @chaunguyen8202

    2 жыл бұрын

    Same thoughts! I think he made mistakes.

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    The reason for that is because first the table size is num of elements+1 and subsetsum+1. The first element and the sum are going to be zeroth element and zeroth subsetsum. Hence, whenever we consider the formula, we need to go with -1.

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    You can run the code and you will be able to see that it works in this manner.

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    //My Code public static boolean isSubSetSumTabulation(int arr[],int subSetsum){ int n=arr.length; boolean dp[][]=new boolean[n+1][subSetsum+1]; for(int i=0;i

  • @siddhantgupta958
    @siddhantgupta9583 жыл бұрын

    🔥🔥🔥🔥🔥🔥🔥🔥🔥

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    :)

  • @rakshith3547
    @rakshith35473 жыл бұрын

    Is this problem same as 523. Continuous Subarray Sum in Leetcode?

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Dint check 523. This is the classic problem.

  • @RTX_valorant
    @RTX_valorant3 жыл бұрын

    same as knapsack problem instead of or u can use 0,1 and maximize

  • @techdose4u

    @techdose4u

    3 жыл бұрын

    Yea

  • @kattelanithyasri7727
    @kattelanithyasri77277 ай бұрын

    how to print the subsets

  • @deeptarkoroy6724
    @deeptarkoroy67243 жыл бұрын

    What if we have negative elements?Will we not subtract the greater number?

  • @dineshothamkumar

    @dineshothamkumar

    Жыл бұрын

    I think if the numbers are negative, we will continue to subtract. The results may not be as expected though.

  • @letsdoeverythinginoneweek9398
    @letsdoeverythinginoneweek93983 жыл бұрын

    you can also say that 0 is present in every subset so thats why thats column is true

  • @protyaybanerjee5051
    @protyaybanerjee50513 жыл бұрын

    I think the reason why we hop to [j-nums[i-1] th column and [i-1]th row needs to be explained in a better way. It should clearly say that that we are trying to simulate the recursive call stack of the inclusion of the first element, where we call subsetSum(nums, index - 1, sum - nums[index]). This recursion call HITS a base case of sum = 0 with no other element left in the array to choose from. Hence the row 0 and it gives the same result as our recursion base case. It's not very intuitive as per the current explanation. You have to go back to the recursion to drive home the point.