Ep14- Combination Sum 3 | Medium level Recursion Problem | DSA | Codes available in description

  Рет қаралды 10,839

LearnYard

LearnYard

Күн бұрын

Пікірлер: 104
@arghya_0802
@arghya_0802 2 жыл бұрын
Summary: 1. Today's question is the culmination of Combination Sum-I and Combination Sum-II 2. Instead of having a given vector nums or arr, we are asked to consider numbers from 1 to 9(both inclusive) 3. We can also visualise them to be inside an array but actually we don't to create it and use extra space. 4. Now we need to pass in the void help() the following parameters: 1) i for the element and n for the target sum 2) sumTillNow to calculate the sum we have accumulated till now 3) k for the number of elements we require in our subset 4) vector subset and vector ans 5. Now we will have the base conditions: a) if(k==0) It means we have calculated the number of elements required. Thus check whether sumTillNow== n. If so include it in the subset else simply return b) if(sumTillNow > n) We have a sum which is more than target, and as we don't have negative numbers we cannot form n so we simply return. c) if(i==10) We can have elements till 9 only. So we return 6. Now we pick the i-th element into our subset , increment sumTillNow by i and ask Recursion to do the calculation for i +1 elements. 7. When we return, we backtrack the changes, decrement sumTillNow by i and pop_back() the inserted element. 8. We now ignore the i-th element, so we simply call for i+1 and ask Recursion to do the remaining task. Time Complexity: O(2^N) [ In worst case, we need to include all the elements till 9 to have n] Space Complexity: O(N) [ Height of Recursive Tree]
@emtiazahmed5333
@emtiazahmed5333 2 жыл бұрын
I just love your summary & i included this into my note🥰🥰
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@daniyalhussain5231
@daniyalhussain5231 Жыл бұрын
This playlist is so so underrated. Fraz you are an absolute legend.
@aasifali9139
@aasifali9139 2 жыл бұрын
bhaiya, i dont think you realize how much you are helping me and others by making this gem series. Absolutely Love it. Thx a lot for the effort you are putting in your videos for us. THANKS again..............
@nithins3895
@nithins3895 2 жыл бұрын
I have done this differently And now im seeing your code is more optimized... Thanks for the HW prblms so that we can try and then we can see your way of doing and learning the things clearly Thanks for the video Bhai
@rounaq_khandelwal
@rounaq_khandelwal Жыл бұрын
Loving these series!!
@maazulhaque7293
@maazulhaque7293 2 жыл бұрын
Episode - 14 Done Thanks Fraz bhaiyya
@alien65629
@alien65629 Жыл бұрын
solved it by myself with the help of previous combination codes. THANKS FRAZ Bhaiya 😄
@davv-r5b
@davv-r5b 9 ай бұрын
Now In this Type Combination Sum 3 , main change from other types is The Given K value : 1. we have to return vector with k length of elements that sum up to N value: 2. Now main approach for this is to Remember That we have to stop When Our K count expires. 3. And then check whether our sum is N equivalent or Not. 4. Applying Simple Pick And Not-Pick approach . 5. And as we have given that range is 1 to 9 , then there is no element occuring duplicately. 6. And when we will add some element to our Temp Vector , then our Count or K should be change. 7. But not At the time of Not-Picking the element , because the no of elements remains same . /// This is the Summary Of this Lecture /// For more clarity Refer To CombinationSum1 and CombinationSum2 Problems First
@jayantmishra6897
@jayantmishra6897 2 жыл бұрын
rarely i subscribe any channel but whatever content that you are providing makes me to subscribe this channel .
@DPCODE72
@DPCODE72 2 жыл бұрын
For the first on Utube who is bringing a quality of good understanding video over the Recursion if he I will keep teaching us like this insane way then it is gonna be 🔥!!
@mohdumar6990
@mohdumar6990 2 жыл бұрын
Now, I understand combination concept using recursion 👍
@SahilVanarse-n4x
@SahilVanarse-n4x 7 ай бұрын
Because of him I am able to solve the next questions ...logic building 💪💪
@nitigyajoshi4658
@nitigyajoshi4658 11 ай бұрын
sumTillNow can be incremented in function call as well. This was really intuitive. Thanks for the great explaination.
@ranitbandyopadhyay
@ranitbandyopadhyay 2 жыл бұрын
Was not available yesterday. As more and more constraints are introduced, the problems are getting more and more interesting and your explanation also. Good work.
@jayantmishra6897
@jayantmishra6897 2 жыл бұрын
and i have one suggestion for you is that is please display the question for a moment so we get little more idea about that.i know before you start explaining you explain about the question very well but this will be additional point for us.
@webtechnology6439
@webtechnology6439 2 жыл бұрын
Sir, I am self-building logic without a video watch. Verry Exited 💥💥💥
@ankushladani496
@ankushladani496 2 жыл бұрын
Now Understanding Recursion in a good way. Thank you Bhaiya....
@Abhishek-fo3fc
@Abhishek-fo3fc 2 жыл бұрын
Done Understood ❤✅
@surgeonofdeath8199
@surgeonofdeath8199 2 жыл бұрын
lol i used the trick u used in first question named combination and it worked then checked out ur solution it is same really glad that i was able to do a medium level question myself this time
@priyanshusingh8971
@priyanshusingh8971 2 жыл бұрын
Completed lecture and Commeting for better reach
@aashuvyas786
@aashuvyas786 2 жыл бұрын
very Great Series! i was able to solve this problem wihtout even seeing this video just with help of you previous videos
@AtomicAkshay
@AtomicAkshay 2 жыл бұрын
Notes: The problem requires understanding of both subset and combination problems, once we have that it is somewhat straightforward to solve, important thing was to identify the base conditions for the recursion. Time Complexity: O(n ^ 9) Represents upper bound, although runtime complexity might be lesser due to presence of k Space Complexity: O(n) Excluding size of result array
@avadhutlohar5181
@avadhutlohar5181 2 жыл бұрын
#EP_14 Completed Consistency OP 🔥🔥🔥 Congrats for 10K❤ Rise and Shine 🌟
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@ratnasanjay
@ratnasanjay 2 жыл бұрын
Thankyou bhaiya for this session
@sarojgupta5562
@sarojgupta5562 2 жыл бұрын
Fraz bhaiya i am following ur dsa course and its really helpful...thank u for all the content and consistency..thank u bhaiya
@sanjeevkumar-pk1ko
@sanjeevkumar-pk1ko 2 жыл бұрын
If u know completely comb. sum 1, 2 then this problem just take 2 mins : just add some new base conditions void fun(int i,int k,int tar,int sum,vector & subset,vector & ans){ if(i>10){return;} if(tar==sum && subset.size()==k){ ans.push_back(subset); return; } if(subset.size()>k)return; //taking i in ans subset.push_back(i); sum+=i; fun(i+1,k,tar,sum,subset,ans); //backtrack subset.pop_back(); sum-=i; fun(i+1,k,tar,sum,subset,ans); } vector combinationSum3(int k, int n) { vector ans; vector subset; fun(1,k,n,0,subset,ans); if(ans.size()==0){} return ans; }
@it_08amanagarwal35
@it_08amanagarwal35 2 жыл бұрын
Excellent lecture bro sorry today I am late to comment as I watch the video but intuition behind question is helping me to solve more no of questions❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤❤
@mdsufyankhan1029
@mdsufyankhan1029 2 жыл бұрын
L14 done ✅✅ Consistency++ 🔥🔥
@yashpadiyar4952
@yashpadiyar4952 2 жыл бұрын
Thankuuuuu ,luvv u bhaiya🤗🤗♥️
@Lucifer-xt7un
@Lucifer-xt7un 2 жыл бұрын
Congratulations for 10k subscribers 🤩🥳😍
@anuraggulati2167
@anuraggulati2167 2 жыл бұрын
lecture 14 done waiting for the next lecture👌👌 feeling confident now in recursion 😎😎🙌💚💚
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@sadikahmed3045
@sadikahmed3045 2 жыл бұрын
Congratulations 👏🎉🎉 for 10k
@chiragkarnwal6740
@chiragkarnwal6740 2 жыл бұрын
Thanks for the lecture sir💝
@Gauravkumar-kc6xh
@Gauravkumar-kc6xh 2 жыл бұрын
Great
@cinemaclockwork215
@cinemaclockwork215 2 жыл бұрын
It's really helpful
@jayantmittal6665
@jayantmittal6665 2 жыл бұрын
Awesome Content!
@mohitroshan3856
@mohitroshan3856 2 жыл бұрын
Ep 14 done ✌️
@sagarpokhriyal6926
@sagarpokhriyal6926 2 жыл бұрын
Lecture 14 Completed ☑ Congratulations bhaiya for 10k. Many more to come💫 #dsabyfaraz☀
@divyanshsagar
@divyanshsagar 2 жыл бұрын
Episode 14 done! 🔥🔥
@singla__sisters2928
@singla__sisters2928 2 жыл бұрын
Nice Explanation, Please discuss contest questions as wellll
@satyammishra6356
@satyammishra6356 2 жыл бұрын
Ep-14 Done ✅
@ShubhamKumar-lf7ed
@ShubhamKumar-lf7ed 2 жыл бұрын
u are great sir
@anishsingh4750
@anishsingh4750 2 жыл бұрын
Present bhaiya!
@klvp_techie
@klvp_techie 2 жыл бұрын
Logic: For every element of an array we have two choices, either to consider it or ignore it if we consider the element update the sum and add it to subset and ask recursion to do the rest and undo all changes you did earlier (# Backtracking) if we ignore it , ask the recursion to do remaining task Base Condition: if sum > target return if length of subset == required check for the sum == target save in ans and return Code: def helper(i,a,k,b,sumTillNow,subset,ans): if sumTillNow > b: return if k == 0: if sumTillNow == b: ans.append(subset[:]) return # if k < 0: # return # if sumTillNow == b: # if k == 0: # ans.append(subset[:]) # return if i > a: return #consider the i sumTillNow += i subset.append(i) helper(i+1,a,k-1,b,sumTillNow,subset,ans) sumTillNow -= i #not considering i subset.pop() helper(i+1,a,k,b,sumTillNow,subset,ans) a = 9 # upper bound of input k = 2 # required length of subset b = 6 # target sum ans = [] subset = [] sumTillNow = 0 helper(1,a,k,b,sumTillNow,subset,ans) print(ans)
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@uavishal777
@uavishal777 2 жыл бұрын
Best Explanation 🔥🔥
@LearnYardYT
@LearnYardYT 2 жыл бұрын
Glad you liked it
@riyagoel4282
@riyagoel4282 2 жыл бұрын
best content
@vishalgowrav
@vishalgowrav 2 жыл бұрын
Episode 14 completed! Combination Sum III Here, The problem is the combination of previous two problem but here we want to return the subsets in which the sum shd be equal to n and count of subset cannot exceed k so in order to achieve it We are incrementing sum and Decrementing k (same as previous problems) and in the base condition we have to check for both sum and k using nested if. Time complexity:- O(2 pow n) Space complexity:- O(n)
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@isikamaiti9116
@isikamaiti9116 2 жыл бұрын
14 done ✅
@someshkharat5849
@someshkharat5849 2 жыл бұрын
hii fraz..appreciate everything u r doing for us..just want to ask u if u could please explain the backtracking lil bit more..
@LearnYardYT
@LearnYardYT 2 жыл бұрын
Yes in coming episodes i will
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@manikgoel9953
@manikgoel9953 2 жыл бұрын
Thanks you bhaiya
@NikhilTiwari-to7sv
@NikhilTiwari-to7sv Жыл бұрын
sir please make a playlist on stacks and queues
@mohdsaadalikhan7209
@mohdsaadalikhan7209 2 жыл бұрын
if(k>9-i+1){// required k numbers > remaining numbers return; } this base condition can also be added to further optimise
@santoshkumarpaul5304
@santoshkumarpaul5304 2 жыл бұрын
Bhaiya plz solve leetcode example
@aveermukherjee6419
@aveermukherjee6419 2 жыл бұрын
Sir will you provide video explanation for the test problems. I was not able to do two problems. It would be very helpful. And sir you said that you will be starting a basic course consisting of array algos binary search etc. It will be very helpful if you start it early.
@kamranwarsi12b22
@kamranwarsi12b22 2 жыл бұрын
In the question it is mentioned we cannot use same numbers between 1 to 9 , so can we use that while condition while(i+1==i && i
@ashokbhardwaj681
@ashokbhardwaj681 2 жыл бұрын
Bhaiya beginner series kab se start hogi pls 🙏 reply
@anirudrabrahma_0971
@anirudrabrahma_0971 2 жыл бұрын
What about exam questions solution discussion...??btw enjoyed another nice video ❤️
@ecs185_shaileshbharti3
@ecs185_shaileshbharti3 2 жыл бұрын
Reach++: ✌️💥
@yashbahuguna8135
@yashbahuguna8135 2 жыл бұрын
done for day 14
@shalimar_mehra
@shalimar_mehra 2 жыл бұрын
Present ! ✔🙌 ok ! It Was Pretty Good but I'm Trying ! I'm facing so many problems ! Can you sir please make an video on [ How to Build logic in program so it was help me for solving my questions ] Thanks a lot sir for this lovely video ! I'm trying my best ! 🙌
@mohdkhaleeq7468
@mohdkhaleeq7468 2 жыл бұрын
Fraz bhai teach Greedy Algorithms topic also
@ksankethkumar7223
@ksankethkumar7223 2 жыл бұрын
What is the time complexity of this problem? is it one among these two O(k*9^k) or O(n^2)? Or what is the correct time complexity?
@DTMASUYASHMISHRA
@DTMASUYASHMISHRA 2 жыл бұрын
Sirr Maine pehle ekk vector of int bana liya usme 1to 9 element daal diye arr usi m pick and ignore it khela ar sum karta gya pehle question jaise arr sari base condition laga dii arr shi hoo gya
@ammysaini10
@ammysaini10 2 жыл бұрын
👌❤️
@vicky-xf5nx
@vicky-xf5nx 2 жыл бұрын
❤️
@jayanthipenugonda7274
@jayanthipenugonda7274 2 жыл бұрын
why can't we use if(sumTillNow>n || k
@utpaltripathi9577
@utpaltripathi9577 2 жыл бұрын
Another base condition for optimization can be- if( ( n - sum ) < ( k * ( k + 1 ) ) /2 ) return; wait! I am explaining also... (n-sum) : It is remaining sum that we have to include. k : number of elements needed to include their value in sum k * ( k + 1 ) ) /2 : sum of first 'k' elements from 1+2+...+k. (minimum possible sum of unique k elements) So think mathematically, if required sum of k unique elements is less than minimum possible sum of k unique elements, then we can't get our result. Correct me pls I am wrong...
@Lucifer-xt7un
@Lucifer-xt7un 2 жыл бұрын
Consistency ++
@Anonymous-om5ql
@Anonymous-om5ql 2 жыл бұрын
Bhaiya, where is the HW problem link?
@utkarshchauhan5827
@utkarshchauhan5827 2 жыл бұрын
Guys I have doubt that Jaise ki bhaiya ne jab sumtillnow==n wali condition lgayi,to unhone sumtillnow>n waali top wali condition comment kardi.inhone jo reason diya wo satisfiied nhi lga ,kyunki yeh condition to important lagi agar k=7 ho and N=11 Ho aur is case me agar yeh condition na ho to hamara control aur aage badhta jayega jaah iski zaroorat bhi nhi hogi aur complexity bharayega,to please koi mera doubt clarify kardo
@naveen_kotha
@naveen_kotha 2 жыл бұрын
Can I get the Questions which were asked in Recursion Contest 1 as I am unable to attempt it
@yeswanthh5068
@yeswanthh5068 2 жыл бұрын
☺️💚💚🙏🙏🙏
@pn5563
@pn5563 2 жыл бұрын
Hello I'm mech 17 pass out with 57 pointer in garduation after work 2.6 yr looking for switch in IT industry because in 12th I'm Computer science student then because people suggest us in our town so we select mechanical who go in future to switch so after 1 yr of work in mechanical field i looking class but i don't know how to apply or go I don't have Idea then lockdown happens I'm looking offline class now i join Java course .....also while listening on KZbin DSA is important so I'm here after watching ur video please please guide me how to apply for job after completing course of 6 months please 🙏
@harshbardhansingh4141
@harshbardhansingh4141 2 жыл бұрын
Bro how to get an internship for a 2nd year student I mean where and how to apply because we don't have any specific experience in the role and the Company how to select us....bcoz sab koi bol dete hai ki ye karlo woh karlo interest pai koi v skill pey sikh kar ke internship kar lo but koi ye nahi batata ki kaise apply kare...itni bheed main hum kaise uss company Mai as a fresher internship paye... Can you make a complete separate video in this topic...🥺🙏
@emtiazahmed5333
@emtiazahmed5333 2 жыл бұрын
Bro i wait for 2h 🙃... Aj kitney lare kyu ho giya? Everything is fine??
@LearnYardYT
@LearnYardYT 2 жыл бұрын
When I rendered the video it didn't come out fine. Then re-rendered, it took time
@RajputAnkit11
@RajputAnkit11 2 жыл бұрын
sad today i am not able to solve and watch this video will do tomorrow sad
@BurhanAijaz
@BurhanAijaz 2 жыл бұрын
Day 14 bhaiya aaj itna late kyu, sab khairiyat
@ayan84240
@ayan84240 2 жыл бұрын
First
@comic_forever
@comic_forever 2 жыл бұрын
aaj no homework problem bhaiya?
@vivekpaanchal
@vivekpaanchal 2 жыл бұрын
New series kab aari hai ?? google join kar ke channel bhul gye 🥲🥲
@LearnYardYT
@LearnYardYT 2 жыл бұрын
Nahi bro jaldi ayegi Was working on leadcoding.in/ Do check out
@vivekpaanchal
@vivekpaanchal 2 жыл бұрын
@@LearnYardYT kal video aate hi dekh liya tha 😌❤️ , so bhi Jaya karao raat ko bhaiya 🥲🥺
@dashundev1586
@dashundev1586 2 жыл бұрын
Uploaded late so watching late
@akashyadagouda896
@akashyadagouda896 8 ай бұрын
missing Striver here
@dashundev1586
@dashundev1586 2 жыл бұрын
And there’s no notification
@RajputAnkit11
@RajputAnkit11 2 жыл бұрын
i worte my own code just forget to stop when i becomes 10
@akashnigam5321
@akashnigam5321 2 жыл бұрын
Bhai agar tu nhi hoga to pata nhi recursion kaise samajh pate 🥺
Live session #2 | Contest discussion | Doubts
42:44
LearnYard
Рет қаралды 4,2 М.
coco在求救? #小丑 #天使 #shorts
00:29
好人小丑
Рет қаралды 34 МЛН
ТВОИ РОДИТЕЛИ И ЧЕЛОВЕК ПАУК 😂#shorts
00:59
BATEK_OFFICIAL
Рет қаралды 6 МЛН
Combination Sum - Backtracking - Leetcode 39 - Python
15:10
NeetCode
Рет қаралды 326 М.
The Backtracking Blueprint: The Legendary 3 Keys To Backtracking Algorithms
13:44
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 199 М.
Combination Sum iii | LeetCode 216 | C++, Java, Python
23:00
Knowledge Center
Рет қаралды 11 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
How to STUDY so FAST it feels like CHEATING
8:03
The Angry Explainer
Рет қаралды 1,9 МЛН