DP 15. Partition Equal Subset Sum | DP on Subsequences

  Рет қаралды 237,961

take U forward

take U forward

Күн бұрын

Пікірлер: 744
@takeUforward
@takeUforward 3 жыл бұрын
I need your support, and you can do that by giving me a like, and commenting "understood" if I was able to explain you. Keeping a like target of 500 ❤✌🏼
@pervejmia8240
@pervejmia8240 2 жыл бұрын
@Striver , can you please a Linked List playlist? This is the most confusing topics for interview preparation i think..
@vishalshandilya3984
@vishalshandilya3984 Жыл бұрын
yes i did
@thisismr900
@thisismr900 Жыл бұрын
khub bhalo striver bhaiya, keep striving harddddd
@AshwinHarish-u4t
@AshwinHarish-u4t Жыл бұрын
Sir I have a doubt. if the first sub problem gives true and second sub problem gives false. Then result will be true since we are not passing the sub problem again to find right sub array is equal or not and also the first sub problem is true so we will give true as answer but the result is false. So it is correct?
@chanchalroy3417
@chanchalroy3417 Жыл бұрын
Understood
@sahilgagan2242
@sahilgagan2242 2 жыл бұрын
28% done ...... now i feel confident .. THANKS striver bhaiya for this ..... i pray u will achieve everything u want ..... god will bless u always .... u help student who cant afford courses ....
@abdulnafe6442
@abdulnafe6442 Жыл бұрын
I hava doubt please help ! In memoization technique , when to declare a 2d array and when to declare 1d array to store previous answers. Like I cannot find out which type of array should I declare . Thanks.
@M10-r8q7h
@M10-r8q7h Жыл бұрын
@@abdulnafe6442 if there are two variable change in basic recursion like findsum(n-1,k-1) then 2d dp else if there is only one variable change in recursive function like fibonaci(n-1) then 1d dp
@23cash86
@23cash86 Жыл бұрын
@@abdulnafe6442 after writing recursive code, look at all parameters, if values of only 1 parameter(eg.index) keeps changing it is 1d dp, declare 1d array ... if two parameters change (e.g. index,target) then 2d array should be declared.
@ok-jg9jb
@ok-jg9jb Жыл бұрын
@@abdulnafe6442 Don't try to write memorization first try to do recursion and see what are the parameters that are changing and make memorization. You will get it
@KunalSingh-kn2ij
@KunalSingh-kn2ij Жыл бұрын
Solved this question without watching the video! DP was nightmare for me before watching your playlist. Thanks Striver.
@Gokul-gkl
@Gokul-gkl Ай бұрын
is it?
@vikasgupta6701
@vikasgupta6701 2 жыл бұрын
Your video makes the tough one's look so easy. When I started with this problem, I was confused on how to proceed with this. Once, I saw the explanation, got to know that this is a new version of previous question. Thanks!!
@guptashashwat
@guptashashwat Жыл бұрын
It is important to check always if(arr[0]
@ramanahlawat398
@ramanahlawat398 Жыл бұрын
true
@utkarshverma3314
@utkarshverma3314 Жыл бұрын
@@samualhalder can you explain this condition to me, the prev question worked without with this condition whereas this one won''t
@rishabhraj8233
@rishabhraj8233 Жыл бұрын
@@utkarshverma3314 so with this condition we are checking that dp[0][arr[0]] is actually present in dp matrix because the size of row is equal to sum and if we do not check this it will go out of bounds and give error'
@shibainu7500
@shibainu7500 8 ай бұрын
Yea I was also scratching my head to solve the runtime error until I saw the full video and came to know about this condition.
@ganeshkamath89
@ganeshkamath89 2 жыл бұрын
Thanks Striver. Understood. I think it is better to take an unordered_map instead of vector. Like this: unordered_map prev, curr; instead of vector prev(k + 1, false), curr(k + 1, false); because target value 'k' can be really large and cause lot of space wastage.
@spytonic4171
@spytonic4171 3 жыл бұрын
you are a gem to the community bro plz continue this trend after following your videos I'm improving logic building the way you teach and the efforts you are keeping are just amazing expecting a like from you :)
@rishabhgupta9846
@rishabhgupta9846 2 жыл бұрын
understood,mapping of new problem with the problems we have already solved is very much important
@preetisahani5054
@preetisahani5054 Жыл бұрын
Understood. Awesome explanation! thought hard but still didn't come up with your logic. You made it so simple.
@stith_pragya
@stith_pragya Жыл бұрын
UNDERSTOOD..............Thank You So Much for this wonderful video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
@shivangmishra1978
@shivangmishra1978 3 жыл бұрын
You have a very long life I picked up my phone after doing some dp question to check if Bhaiya posted video or not and daam immediately i received notification of your video 😍😌sukoon
@Ashutosh_75
@Ashutosh_75 Жыл бұрын
Great explanation didn't even need to see the whole video just saw the first 3 minutes and I was like it is too easy .
@girishbhargava6367
@girishbhargava6367 2 жыл бұрын
Best playlist of DP, that can ever exist anywhere
@abhijeetbasfore6816
@abhijeetbasfore6816 2 жыл бұрын
without watching this video I have solved the question. easy tha bas sum/2 krna hga. if sum odd return false else subsetsum with sum/2. thank you so much Striver bhaiya
@Sumit-wy4zp
@Sumit-wy4zp Жыл бұрын
Understood ++; Great Explanation .. This is the greatest playlist on Earth. Day 152 ..
@k-AnishChatti
@k-AnishChatti 2 жыл бұрын
Understood !!!! Finally understanding Subset with DP and now I am able to solve Knapsack at 5AM 😁
@ankurbaijal5663
@ankurbaijal5663 2 ай бұрын
Understood !! Solved this question without watching the video!
@aseem-b23
@aseem-b23 Жыл бұрын
Understood and thank you so much Striver ❤
@study-yd6es
@study-yd6es 2 күн бұрын
Amazing Explaination Striverr Sirr
@BharatiSubramanian99217
@BharatiSubramanian99217 2 жыл бұрын
Hey understood. One question is: let's say our array was [1,1,2,3] and target = 4. In the base condition dp[o][arr[0]] = true. We are checking if(arr[0]
@sauravdutta
@sauravdutta 2 жыл бұрын
dp[0][arr[0]] means that if you're at index 0 and the target that you have is equal to the value of arr[0] then it's true. It basically tells that when you're at index 0 and if the target is 1 in our case (which is arr[0]) then mark it as true.
@well....7751
@well....7751 2 жыл бұрын
I got a different recursion logic , although its a bit lengthy. Here each value can be included in subset 1 or in subset 2.So we write recursion for it and try to find wether for any subsets both of their sums are equal or not.
@codingachinilgtifirbhikrrh9009
@codingachinilgtifirbhikrrh9009 2 жыл бұрын
i also did the same thing but i am not able to memoize it can u tell me what did u do?
@vaishnavi9755
@vaishnavi9755 2 жыл бұрын
Yes same.. but how to create tabulation for the same any idea on that??
@sayakghosh5104
@sayakghosh5104 2 жыл бұрын
@@vaishnavi9755 You can memoize/tabulate with the help of 3D Dp, dp[index][sum1][sum2], but the constraints are too high, it'll give you memory limit exceeded.
@vaishnavi9755
@vaishnavi9755 2 жыл бұрын
@@sayakghosh5104 Okay.. Got it.. Thanks for the answer!
@rishabhinc2936
@rishabhinc2936 Жыл бұрын
i tried using what u said but its giving me runtime and tle .can u help find error bool f(int arr[],int n ,int sum1 ,int sum2,vectordp) { if(n==0) { return abs(sum1-sum2)==arr[0]; } // pick if(dp[n][sum1][sum2]!=-1) { return dp[n][sum1][sum2]; } bool pick = f(arr,n-1,sum1+arr[n],sum2,dp); // not pick bool not_pick = f(arr,n-1,sum1,sum2+arr[n],dp); return dp[n][sum1][sum2]=(pick || not_pick); }
@udaytewary3809
@udaytewary3809 Жыл бұрын
Understood bhaiya ❤❤❤ I solved this question on my own bhaiya 🎉🎉 really happy 😊😊 And this is only possible is because of u❤❤
@yashshukla1637
@yashshukla1637 Ай бұрын
Very well explained brotha! love your content!!!!!
@dharmeshpoladiya9047
@dharmeshpoladiya9047 2 жыл бұрын
Understood 💯💯 Great Explanation. Thank you very much for all you efforts🔥🔥
@GurshaanpreetSingh-b5p
@GurshaanpreetSingh-b5p 6 ай бұрын
we have to set cur[arr[0]] instead of prev[arr[0]] , then it will work correctly otherwise it may give wrong answer ex -> for 1 ,2,5 where target =4 , it will give true but answer should be false Nice video Btw 👍👍
@MukeshKumar-cc3uh
@MukeshKumar-cc3uh Жыл бұрын
Loving the playlist. "Understood" Sir Striver.❤
@prabhakaran5542
@prabhakaran5542 11 ай бұрын
Understood ❤
@theclashbegin4002
@theclashbegin4002 2 жыл бұрын
Whatever you teach it's just osam .Understood .Thanks for this playlist.
@channelname4394
@channelname4394 3 жыл бұрын
Best explanation. understood , hope this channel reaches more people
@lakeshkumar1252
@lakeshkumar1252 Жыл бұрын
solved by just getting hint in the first half thanks bhaiya
@ntgrn-pr5yx
@ntgrn-pr5yx 3 ай бұрын
understood , thank you striver
@chetanchaudhary1017
@chetanchaudhary1017 2 жыл бұрын
Thanks Striver !!! For such wonderful DP series
@raghavmanish24
@raghavmanish24 5 ай бұрын
understood.....waiting for finish this series as soon as possible
@nithish_raina
@nithish_raina 2 жыл бұрын
The question might have been more clear by specifying (S1 U S2 ) = A where Si is a subset and A is the original array.
@ishantrivedi5588
@ishantrivedi5588 Жыл бұрын
Correct! In the question they've not said that both subset should make up the entire array
@vikasbagri1225
@vikasbagri1225 2 жыл бұрын
understood it very well thanks for this amazing DP series
@vanshikasoni6950
@vanshikasoni6950 3 ай бұрын
Understood Bhaiya... Thank you!
@shreyashtech8556
@shreyashtech8556 10 ай бұрын
bro doing gods work
@AdityaPandey-ek5vq
@AdityaPandey-ek5vq Жыл бұрын
Ban rhe ques 🙏🏻🙏🏻 . Thank you!!!
@hashcodez757
@hashcodez757 6 ай бұрын
"UNDERSTOOD BHAIYA!!"
@paveshkanungo6338
@paveshkanungo6338 Жыл бұрын
understood! Thank you Striver!
@junaidkhalidi-mw1zs
@junaidkhalidi-mw1zs 2 жыл бұрын
At end u added a if condition but I think its just : if(arr[0]==k)prev[arr[0]]=true . It should not be if(arr[0]
@probro2540
@probro2540 2 жыл бұрын
understood Also, thank you for the song at the end. It's a nice song and has been added to my playlist 😂
@dhruvkaran9724
@dhruvkaran9724 2 жыл бұрын
bro able to solve it myself ... with exactly same way u explained .... looks like I started thinking like legend :D hhehehe
@sujalgupta6100
@sujalgupta6100 2 жыл бұрын
At 8:33 why using condition if( arr[0] == k ) instead of if(arr[0]
@nithish_raina
@nithish_raina 2 жыл бұрын
It has to be
@Divyendu-by7te
@Divyendu-by7te Жыл бұрын
@@nithish_raina can you please explain this to me?
@earningonlinevip8147
@earningonlinevip8147 2 жыл бұрын
understood sir thank you sir i love you sir mzaaaaaaa gya padhke ....ab to lg rha h jaisse dp mere bacche jaisa h
@Amitkumar-yh2uw
@Amitkumar-yh2uw Жыл бұрын
cool content, very crisp and clear (Y)!
@ananthalakshmi
@ananthalakshmi 10 ай бұрын
@takeUforward Striver, your classes are amazing . Please keep on going......💥💥💥💥💥💥. I have a doubt like what if array contains arr = [100] ?? ? does the above code support above test case?
@ranasauravsingh
@ranasauravsingh 2 жыл бұрын
UNDERSTOOD... ! Thanks striver for the video... :)
@shauryakumar6372
@shauryakumar6372 2 жыл бұрын
why we are checking arr[0]
@HammyHues
@HammyHues 6 ай бұрын
@shauryakumar6372 exactly!! same doubt.
@kon_humein
@kon_humein 22 күн бұрын
​@@HammyHuesbecause bottom up approach use kiya hai with space optimisation bro memorization nhi
@kathanvakharia
@kathanvakharia Жыл бұрын
Understood...Completed 15/56
@shubhamraj25
@shubhamraj25 2 жыл бұрын
8:00 that condition is necessary to pass all test cases for the same question in LeetCode
@arreactor2146
@arreactor2146 2 жыл бұрын
Not necessary, I have submitted same question on leetcode without this condition. Just comment this line // if(nums[0]
@ritikshandilya7075
@ritikshandilya7075 7 ай бұрын
Thankyou so much Striver
@shreyashtech8556
@shreyashtech8556 10 ай бұрын
understood at its peak
@adarshanku7988
@adarshanku7988 2 жыл бұрын
Please make a video on "Partition to K equal Sum subsets"........i can't find any dp solution understandable. Please please please make a video on its dp approach god please. Humble request bhaiya, please. Btw understood 🙏.
@katamsreeja6744
@katamsreeja6744 2 жыл бұрын
Understood it clearly. Thank you so much.
@arihantjammar8888
@arihantjammar8888 Жыл бұрын
Understood 😃😊
@Hrushi_2000
@Hrushi_2000 Жыл бұрын
Understood. Thankyou Sir.
@gunduboinadileep9523
@gunduboinadileep9523 Жыл бұрын
understood, Sir!
@momilijaz271
@momilijaz271 2 жыл бұрын
man! you are good at DP!
@adityajoshi3922
@adityajoshi3922 2 жыл бұрын
that's why he made the course
@OpenMinded2509
@OpenMinded2509 Жыл бұрын
can we do it if no target was given just equal sum subset
@jyothiyadav2595
@jyothiyadav2595 Жыл бұрын
Understoooood ❤❤❤❤❤❤❤❤
@lambar0
@lambar0 2 жыл бұрын
Striver, can you gather the indices for one valid solution from the tabulated dp table ? As one question is to return a solution subarray?
@piyushsaxena6243
@piyushsaxena6243 3 жыл бұрын
understood, amazing explanation.
@varindersingh_
@varindersingh_ 2 жыл бұрын
Understood. Thanks for creating the playlist.
@Yoshitha-fq9en
@Yoshitha-fq9en Жыл бұрын
Really Nice
@meetsaini3069
@meetsaini3069 22 күн бұрын
Understood sirji
@SnehJoshi19
@SnehJoshi19 2 жыл бұрын
What if we have given divide in to K subset ?
@mypherleetcoder2267
@mypherleetcoder2267 2 жыл бұрын
Understood , awssmm Videos (your DP series is LIT !!)
@parthib.1555
@parthib.1555 Жыл бұрын
Understood
@AbhishekKumar-cv1dh
@AbhishekKumar-cv1dh Жыл бұрын
Understood🔥🔥🔥🔥
@SD-vk3ko
@SD-vk3ko 2 жыл бұрын
Hey Striver... THANK YOU So much for all the efforts. I just wanted to know, what accessories you use to make the video?
@aps8874
@aps8874 7 ай бұрын
Thank you so much!
@SajanKumar-ec2us
@SajanKumar-ec2us 9 ай бұрын
i did not understood when if a subset is present in array then other equal sum subset will present definitely also discuss is it memoisation problem
@nithishlelll9664
@nithishlelll9664 Жыл бұрын
Understood!!😄
@himanshuagrawal8012
@himanshuagrawal8012 2 жыл бұрын
SAMJH GYA BHAIAYA #UNDERSTOOOOOOOOOOOOOOOOOOOOOOOOOOOODDDDDDDDDDDDDDD
@BishtiGanika
@BishtiGanika Жыл бұрын
You are a SUPERHERO 🧡
@Nitishsharma-y7c
@Nitishsharma-y7c Жыл бұрын
Understood👍👍
@thisismr900
@thisismr900 Жыл бұрын
kHUB BHALO STRIVER BHAIYA STRIVE HARDDDDD
@anirvangoswami
@anirvangoswami Жыл бұрын
Maan Gaye guru.sticker
@gunjjoshi5687
@gunjjoshi5687 Жыл бұрын
good observation
@ratinderpalsingh5909
@ratinderpalsingh5909 2 жыл бұрын
Understood, sir. Thank you very much.
@lakshyasharma7448
@lakshyasharma7448 3 жыл бұрын
correct me if i am wrong but isn't the operation : prev = cur a Theta(n) operatoin...would not it be better if we could just move between two arrays ....instead of keeping the previous row in prev and current row in cur here is my implementation ...do correct me if you think what i am saying is wrong bool check(vector &arr,int n,int sum,vector &dp){ dp[0][0] = 1; dp[1][0] = 1; int init =0; for(int i=0;i
@takeUforward
@takeUforward 3 жыл бұрын
Yes works.
@prakhardixit1597
@prakhardixit1597 Жыл бұрын
In the current problem, would the arr[i] be greater than the target only if we have negative elements? Since we are obtaining the target by summing the elements up? If there are negative elements in the array, the range of target in the defined dp will have to change to 2 * target + 1, correct? And we will need to offset each sum value value by adding target to it to make it within the positive range of [0, 2*target]?
@VIKASRAJPUT-nr4nw
@VIKASRAJPUT-nr4nw Жыл бұрын
sir poori dp series mein yahi lal kurta hai isko badal lo yrrrr pehle....thanks for this dp series.....suppport from IIITA
@himanshubanerji8800
@himanshubanerji8800 Жыл бұрын
Understood!
@sanjanashrees30
@sanjanashrees30 7 ай бұрын
Does this work for array with negative values?
@rishabhagarwal8049
@rishabhagarwal8049 2 жыл бұрын
understood Sir Thank you very much
@kevinkumar7788
@kevinkumar7788 3 ай бұрын
UNDERSTOOD
@falgunitagadkar4097
@falgunitagadkar4097 Жыл бұрын
Understood Striver!✌
@VIJAYSHARMA-dh6vo
@VIJAYSHARMA-dh6vo 4 ай бұрын
Understood sirrrr
@mdrejaulhasan5108
@mdrejaulhasan5108 10 ай бұрын
What about arr size is 1. Isn't it an edge case.
@nimmalavishnu3044
@nimmalavishnu3044 2 жыл бұрын
You r genius man...U r gem
@Hard2Smart_Coder
@Hard2Smart_Coder Жыл бұрын
Understood😀
@tech_wizard9315
@tech_wizard9315 3 жыл бұрын
By when entire dp series will be uploaded
@King-ul4nb
@King-ul4nb 3 жыл бұрын
March Tak shayad ho jayega
@TusharKukreti-y1x
@TusharKukreti-y1x 25 күн бұрын
understood....
@saswatmishra4055
@saswatmishra4055 2 жыл бұрын
The lectures are very good, but i am finding it difficult to understand the tabulation part of any video(will rewatch these problems in a few months and may be i will understand).
@Codekage1
@Codekage1 2 жыл бұрын
same bro
@kshitijgupta592
@kshitijgupta592 Жыл бұрын
Hey, can you make a video about what should be the size of our DP? I'm always confused between n or n+1
@kanishkdadhich1720
@kanishkdadhich1720 Жыл бұрын
Depends, whether you require n states or n+1 states. To be on a safer side, generally ppl declare n+1 size array
@gp7060
@gp7060 2 жыл бұрын
Is way of finding subsequence and subset are same pick and not pickup?
@utkarshverma3314
@utkarshverma3314 Жыл бұрын
how exactly is the condition if(arr[0]
@AshishYadav-ql3up
@AshishYadav-ql3up 6 ай бұрын
loved it
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН
To Brawl AND BEYOND!
00:51
Brawl Stars
Рет қаралды 17 МЛН
Tuna 🍣 ​⁠@patrickzeinali ​⁠@ChefRush
00:48
albert_cancook
Рет қаралды 148 МЛН
Fastest Way to Learn ANY Programming Language: 80-20 rule
8:24
Sahil & Sarra
Рет қаралды 966 М.
AI Is Making You An Illiterate Programmer
27:22
ThePrimeTime
Рет қаралды 207 М.
DP 18. Count Partitions With Given Difference | Dp on Subsequences
18:00
DP 43. Longest Increasing Subsequence | Binary Search | Intuition
16:27
DP 17. Counts Subsets with Sum K | Dp on Subsequences
36:57
take U forward
Рет қаралды 244 М.
黑天使被操控了#short #angel #clown
00:40
Super Beauty team
Рет қаралды 61 МЛН