Тёмный

Lecture37: Recursion - Subsets / Subsequences of String [Theory + Code] 

CodeHelp - by Babbar
Подписаться 592 тыс.
Просмотров 315 тыс.
50% 1

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 535   
@virisharma7752
@virisharma7752 2 года назад
Bhaiya you teach things in such a manner that they don't seems difficult at all. Respect++
@human75788
@human75788 2 года назад
After understanding the technique and logic of the 1st problem I solved the 2nd problem myself without even watching your logic and solution. Thanks for giving me the confidence, Sir. Hope you get well soon. Like you, I am also sick right now and pushing hard towards recovery but I made sure to watch your videos and practice coding myself😊
@tanmaysinghal8370
@tanmaysinghal8370 2 года назад
sahi h yrr, m java mein code kar rha tha, 1st code hi nahi chala...
@rishavpayasi6292
@rishavpayasi6292 2 года назад
denge.....
@jonny._.1313
@jonny._.1313 2 года назад
Your telegram please
@SwatejTech
@SwatejTech Год назад
@@rishavpayasi6292 erripu......
@satveersaini1099
@satveersaini1099 2 года назад
Thanks Bhaiya for consistency of this 10 days recursion serial for deduction Attendance marked 💯💯
@anujonthemove
@anujonthemove Год назад
In this and in the DP series, the examples chosen and the sequence in which they have been taught is very logical hence it helps build the concept and the ideas very well. Kudos!
@Ayush_.
@Ayush_. 2 года назад
aapp jaldi se thikk ho jao bhaiya ☺️ ❤️ me to Blindly trust ke sath aapki video dekhta hoo. everyday jaldi se video dekh kar next video ke liye ready rahta hoooo😃 you give us consistency & made us consistent. dill se shukriya ❤️
@samaysarah7417
@samaysarah7417 2 года назад
Me (after watching every promotional parts) : jab aapki dukaan pe free me Shahi Paneer mil raha ho to paisa deke maggie khane koun jaae... 😅😅😅 Thank you bhaiya....💯💯💯💯🌸🌺🌻🌹🌷🌼💐 Itna achha course banane ke liye.. Get very well soon..
@manovmandal3511
@manovmandal3511 Год назад
Phli baar mei samajh nahi aya tha bhaiya, but second time dekha and khud se notebook mei dry run jab kiya toh maja hi agaya solve krke, dusri wali toh khud se hi hogayi! Thank you so much!
@utkarshtambe_10
@utkarshtambe_10 2 года назад
Bhaiya, apka Josh high rakho. Ham log apke videos regularly dekhte hain. Aap hi hamka sahara ho. U r doing great!!! Also, backlog khatam kar raha hu. Din ke 2 videos dekh hi leta hu....
@soumodipsengupta9902
@soumodipsengupta9902 Год назад
Amazing visualization of the problem helped me to understand and appreciate the problem solving, many thanks Babar!
@supersuperhero2449
@supersuperhero2449 Год назад
1st question me, outut bale vector me, only one element, index bala push hona chahiye, phir he 2 elements (1, 2) ek saath kese push ho raha he?
@ayushagrawal205
@ayushagrawal205 Год назад
@@supersuperhero2449 recursion call se bro
@_SahilShah
@_SahilShah 2 года назад
Loved this video alot!! Marked my attendance! Commenting for Better Reach! The Best DSA course ever on youtube!🔥🔥🔥🔥🔥
@aeshwer
@aeshwer 2 года назад
By Include/Exclude logic we cannot solve the case when there are duplicates in input. We need a backtracking logic here
@shubhampathak260
@shubhampathak260 Год назад
Que me diya h ki array unique elements Ka h ....
@RaviRavi-kt9gt
@RaviRavi-kt9gt 10 месяцев назад
You can use additional set data structure here
@ibrahimsohail1963
@ibrahimsohail1963 10 месяцев назад
Bro, a set contains unique elements
@nitin6110
@nitin6110 9 месяцев назад
In set no duplicates
@vikashKumar-rj5ou
@vikashKumar-rj5ou 2 года назад
Bhaiya semesters chal rhe h iski wjh se 10 11 video backlog chal rhi h But you are consistent Thankyou bhaiya
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 года назад
Index >nums.size() q nahi hoga ? Q ki last element pe exit nahi marna hai !
@9852963775aaa
@9852963775aaa 2 года назад
bhaiya maza aagaya saare questions ban gaye ab maza aaraha hai ab shayad kuch hojae thankyou so much bhaiya >>>>>
@luckysharma5485
@luckysharma5485 2 года назад
love u bhai ,Respect from heart....U r teaching us with lot of energy and dedication even when u r infected with corona salute u ...bhai..RESPECT++
@yashbhawsar8347
@yashbhawsar8347 2 года назад
Final year project ke liye kuch series bana do
@rahulsharma2075
@rahulsharma2075 2 года назад
Yes sir please
@oppoplayer7203
@oppoplayer7203 2 года назад
Live with coding because we are begginer
@rasid_khan
@rasid_khan 2 года назад
Sahi hai
@ankitkushwah338
@ankitkushwah338 2 года назад
Yes sir
@Hiarling
@Hiarling 2 года назад
Yes that's needed
@aviratsharma771
@aviratsharma771 Год назад
At first i didn't get the concept at all but after watching this video again after a day now i feel confident and learn this new concept of backtracking.
@shekharjugtwan2810
@shekharjugtwan2810 9 месяцев назад
Isme humne backtracking kyu nahi kari. Output ko empty kyu nahi kra jese humne keypad problem meh kra
@devvarshney1144
@devvarshney1144 2 года назад
vector subsets(vector& nums) { vector ans; int n = nums.size(); for(int i = 0;i
@saqihere
@saqihere 22 дня назад
thanks dude :) please explain inshorts ✨
@debabratabasak6031
@debabratabasak6031 2 года назад
thank you bhaiya aapne humare liye itna accha content create kar rhe ho , woh bhi absolutely free mein. Thank you bhaiya💌🤟
@user-dc8ei2kl7v
@user-dc8ei2kl7v Год назад
if we are not popping out at any time. how are we getting the subsets? The subset problem code will create vector output of redundant values. Leetcode also not catched it. I request leetcode to check it again.
@hindustaniyodha9023
@hindustaniyodha9023 Год назад
Make a function call stack yourself using a smaller test case like { 1 , 2 } . Visualize every single call that is made pushed and popped.
@saumitramuley5170
@saumitramuley5170 2 года назад
Thank you bhaiyya for everything you are doing great work all concepts are clear till this video pray for fast recovery
@ankitsaha9156
@ankitsaha9156 2 месяца назад
Thanks bhaiya, apki waja se ye backtracking samaja aaya, ye bohot dino se samjne ka kosis kar raha tha lekin nhi aaya, sirf apki ye ek video ke waja se aaya, thanks bhaiya
@infernogamer52
@infernogamer52 Год назад
Samajh me aa gaye dono questions bhaiya...
@AmanKumar-io3ev
@AmanKumar-io3ev День назад
Your teaching skill is awesome ❤❤
@sujaysarkar2602
@sujaysarkar2602 Год назад
#include using namespace std; void solve(vector& nums,int index,vector output,vector& ans){ int length=nums.size(); //base case if(index>=length){ ans.push_back(output); return; } //exclude solve(nums,index+1,output,ans); //include int element=nums[index]; output.push_back(element); solve(nums,index+1,output,ans); } int main(){ vector nums={1,2,3}; int index=0; vector output; vector ans; solve(nums,index,output,ans); cout
@Vijay-dz2qt
@Vijay-dz2qt Год назад
bhai es ques me array leke kar skta hai not taking vector
@hindustaniyodha9023
@hindustaniyodha9023 Год назад
@@Vijay-dz2qt it will be complex. So, just use a vector for storing all the possible subsets.
@keshavkapoor1716
@keshavkapoor1716 2 года назад
Truly the best explanation for these problems. No one on youtube has explained it in such an easy way. Bhaiya you are the best
@Anonymous-qf6jn
@Anonymous-qf6jn Год назад
Kya bhai, itni bekar tarike se explain kya pehla wala isne
@anuragpandey8165
@anuragpandey8165 2 года назад
Finally a series worth the time.
@jayant2366
@jayant2366 2 года назад
iss question ko samjhne ke liye maine apne ek ghante idhar udhar kharab kiye aur yahan 2 question 27 min me samjh aa gye.thank you so much bhaiya
@Codes_king
@Codes_king 8 месяцев назад
really so easy question because of you, i taught this concepts of various teacher but cant understood how it's work but today, my all doubts is so clear thankyou Babbar bhaiya love you so much
@KajalSingh-pr2np
@KajalSingh-pr2np 2 года назад
Definitely This is, 🌠 THE BEST DSA SERIES 🌠 Thank you so much bhaiya 🙏
@kushalhedaoo9341
@kushalhedaoo9341 2 года назад
Thank you for this wonderful 10day recursion Awesome series 👏 👌
@dipanshmalhotra564
@dipanshmalhotra564 2 года назад
bhaiya nhi aaye samaj
@VijayPatel-ez4lp
@VijayPatel-ez4lp Год назад
dono question aa gaye samjh mein Bhaiya.Thanks❤
@yashkhatwani3198
@yashkhatwani3198 2 года назад
Subset has 2 to power n elements and subsequence is (2 to power n) - 1 i.e 2^n - 1 because we exclude empty subset from it
@indradip574
@indradip574 2 года назад
If there is a question that will tell that print all the subsequence with the empty string then it will be 2 to power n otherwise your answer is correct
@parth6661
@parth6661 3 месяца назад
bhaiya dono question samaj mein aa gaye
@appsuniverse9976
@appsuniverse9976 2 года назад
Best content to understand Recursion in simple way amazing . Very helpful
@harshitkumar197
@harshitkumar197 Год назад
Dono samjhe aa gye. abb homework karna hai. Thank you for this course. learning a lot
@simplesolutions2621
@simplesolutions2621 2 года назад
Hum padh rhe hai bhaiya❤, aap chinta mat karo..Aap please videos daalte raho..Aap apna 100% do, hum apna 200% dene ko tayaar hai..🔥 Jo bacche videos nhi dekhre abhi.... Wo pakka pichli waali videos ko kar rhe honge abhi bhi..aap chinta mat karo..sab time k saath raftaar pakad lenge... Aap bas 17 march tak khatam kar dena..hum placement lagwake aapko jaldi hi Khushkhabri sunaaynge Mail pe❤ 😇
@umangg2736
@umangg2736 Год назад
thanks for all videos best dsa videos
@ntrsdiaries3928
@ntrsdiaries3928 2 года назад
hats off to your consistency.... marked present🤩🤩
@741ibrahim2
@741ibrahim2 2 года назад
// power set --> bitn manipulation se bhi hosaktahai! class Solution { private: bool CB(int i, int j){ return((i)&(1
@shrutishaw7422
@shrutishaw7422 6 месяцев назад
the way you explain the recursion tree is excellent!!🥰🥰🥰
@prathmeshparteki1016
@prathmeshparteki1016 2 года назад
Bhaiyya dono samjh me aa gaye consistency++ Attendance++
@Nishantpandey-hj2qz
@Nishantpandey-hj2qz 4 месяца назад
for(int =1;i>=0;i++) { cout
@mohdkhaleeq7468
@mohdkhaleeq7468 2 года назад
Bhai aap ke explain karne ka tarika ek dam badia ha Both questions are clear Your course is awesome
@sanjudevi9478
@sanjudevi9478 2 года назад
Loved this video alot!! Marked my attendance! Commenting for Better Reach!
@rishavkumar2302
@rishavkumar2302 2 года назад
Question Subsets :- Time: O(pow(2,n)) Space: O(n*pow(2,n))
@piyushmaheshwari6050
@piyushmaheshwari6050 2 месяца назад
very helpful video bhaiya
@manishmaurya2365
@manishmaurya2365 2 года назад
Bhaiya dry run kar diya karo pls, usse bahot jyada clarity milti hai aur approach jyada din tak yaad bhi rehta hai, average studnts ki need hai voh, usse spoon feeding mat consider karo please.
@nikhilraosahab01
@nikhilraosahab01 2 года назад
THE BEST DSA COURSE
@mr.luxxyandreneo5168
@mr.luxxyandreneo5168 25 дней назад
Why am I always afraid of facing these kind of problems ?? so sad, this problem is too hard to derive the logic, he didn't even say how can we take the observation from output?
@vinodbiradar6127
@vinodbiradar6127 2 года назад
1.Subsets for java. class Solution { public void call_subset(int[] nums,List ans,List first,int index) { if(index>=nums.length) { ans.add(first); return ; } List copyForInclude = new ArrayList(first); List copyForExclude = new ArrayList(first); //exclude call_subset(nums,ans,copyForExclude,index+1); //include int element=nums[index]; copyForInclude.add(element); call_subset(nums,ans,copyForInclude,index+1); } public List subsets(int[] nums) { List ans= new ArrayList();; List output= new ArrayList();; int index=0; call_subset(nums,ans,output,index); return ans; } } 2.Subsequences of String import java.util.ArrayList; class Solution { public static void subsequences_fun(String str,ArrayList ans,String output,int index) { if(index>=str.length()) { if(output.length()>0) ans.add(output); return ; } subsequences_fun(str,ans,output,index+1); char ele=str.charAt(index); output+=ele; subsequences_fun(str,ans,output,index+1); } public static ArrayList subsequences(String str) { // Write your code here ArrayList ans=new ArrayList(); String output=""; int index=0; subsequences_fun(str,ans,output,index); return ans; } }
@LostHero1
@LostHero1 Год назад
class Solution { public List subsets(int[] nums) { List temp = new ArrayList(); List ans = new ArrayList(); solve(nums,ans,temp,0); return ans; } public void solve(int[] nums,List ans,List temp,int idx){ if(idx>=nums.length){ ans.add(new ArrayList(temp)); return; } solve(nums,ans,temp,idx+1); temp.add(nums[idx]); solve(nums,ans,temp,idx+1); temp.remove(temp.size()-1); } }
@pradeepranjan1309
@pradeepranjan1309 Год назад
@@LostHero1 yes... The last backtrack is important here...
@subhamsingh4993
@subhamsingh4993 Год назад
@@LostHero1 can anyone explain why we need to remove the last element in java, while in c++ we don't remove it.
@Vijay-dz2qt
@Vijay-dz2qt Год назад
bhai esko c++ me bta sakta hai array leke not vector , full code jo mai vs code me likh saku
@atharvameher5880
@atharvameher5880 Год назад
Why in java like that not in C++@@subhamsingh4993
@anuraggulati2167
@anuraggulati2167 2 года назад
apki ye wali T-shirt mughe bahut acchi lagi .... video bhi .. maza aagya bhaiya thankyou
@himanshugoyal5239
@himanshugoyal5239 2 года назад
Best Dsa series Bhaiya plz take care of your health Get well soon
@rudrajha1002
@rudrajha1002 Год назад
Bhaiya...kya hee bolun...you have taught me this in a very fine way...😍thanks
@torus151
@torus151 2 года назад
Thanks bro...i was stuck on these type of problems from many days
@Ajay-ei2jo
@Ajay-ei2jo Год назад
Bhaiya dono questions bahut achchhe se samajh me aa gaye...
@sounaksaha1455
@sounaksaha1455 2 года назад
How's the Josh? ... Very high bhaiya.... aise hi content laate rehne... humare saath saath corona bhi ... apka baat mann jayga... Hoping for a soon recovery... #WeLoveBabbar
@shashankshekher4152
@shashankshekher4152 2 года назад
Hello bhaiya, I am watching this series but lagging with lectures. So don't think that we are not watching ❤️
@Vikram-Sharma-
@Vikram-Sharma- 2 года назад
PRESENT SIR ... RI8 NOW AT LECT -36 REACH ++ CONCEPT ++
@vikashkumarvlogsnitj
@vikashkumarvlogsnitj Год назад
//home problem solution 1 #include using namespace std; vectorsolve(string s) { vectorans; long long a=pow(2,s.length()); for(int i=0;i>1; } ans.push_back(output); } return ans; } int main(){ string s; cin>>s; vectorans; ans=solve(s); for(string x:ans) cout
@Hisam007
@Hisam007 2 года назад
Best way of learning recursion ❤️❤️
@patelrajkumarnareshkumar8156
@patelrajkumarnareshkumar8156 2 года назад
subsets using Iterative approch vector subsets(vector& nums) { vector ans; // vector output; int i = 0; // solve(nums , ans , output , i); vector output = {}; ans.push_back(output); while(i < nums.size()){ int size = ans.size(); for(int j = 0 ; j < size ; j++){ output = ans[j]; output.push_back(nums[i]); ans.push_back(output); } i++; } return ans; }
@chuskimemer
@chuskimemer 2 года назад
Watching ur videos regularly daily...But currently I am 10-12 lectures behind... I was busy with my end sems.
@human75788
@human75788 2 года назад
outstanding! Understood every bit of it!
@NoahDevSd
@NoahDevSd 11 месяцев назад
I am having one doubt in question 1... don't we need to pop_back element from output vector while backtracking?
@shekharjugtwan2810
@shekharjugtwan2810 9 месяцев назад
Isme humne backtracking kyu nahi kari. Output ko empty kyu nahi kra jese humne keypad problem meh kra
@udaytewary3809
@udaytewary3809 2 года назад
Dono question bhaut aache se samaj me aye bhaiya 🥰🥰🙏🙏🙏🙏
@DilipKumar-si4ww
@DilipKumar-si4ww 2 года назад
Samaj aaya bhaiya.... bhaiya you told you are very good in aptitude.... so plz think about that also bhaiya... because the way you teach it is super understandable....
@ranupandey8490
@ranupandey8490 11 месяцев назад
I like your teaching playlist more than others💞💞💞💞.
@rahul_singh_rajput3292
@rahul_singh_rajput3292 2 года назад
before rat in maze problem i was nothing understand.. after coming from that question i able to understand what & how this is working... 😋😋..
@harithpatnam5626
@harithpatnam5626 Месяц назад
Thankyou sir we loved it!!!
@Anjan_Raj
@Anjan_Raj 2 года назад
Thanku sooo much bhaiya. ❤️❤️❤️ Take care!!!!
@anishbarnwal5676
@anishbarnwal5676 Год назад
Thankyou bhaiya for this amazing lecture❤️🔥🔥
@shikharyadav4898
@shikharyadav4898 Год назад
JAVA CODE - SUBSET public static void main(String args[]) { int[] arr = { 1, 2, 3 }; List resList = new ArrayList(); List outputList = new ArrayList(); int index = 0; subsets(arr, resList, outputList, index); } private static void subsets(int[] arr, List resList, List outputList, int i) { if (i >= arr.length){ resList.add(outputList); return; } //exclude subsets(arr, resList, new ArrayList(outputList), i+1); //include outputList.add(arr[i]); subsets(arr, resList, outputList, i+1); }
@suar_pilla
@suar_pilla 6 месяцев назад
Incase of Java users, be careful, it wont work without backtracking... public List subsets(int[] nums) { List subsets = new ArrayList(); List subset = new ArrayList(); int index = 0; solve(index,nums,subset,subsets); return subsets; } private void solve(int index, int[] nums, List subset, List subsets) { System.out.println("Index: " + index + " " + subset); if(index >= nums.length){ System.out.println("Index: " + index + " " + subset + " PUSHED"); subsets.add(new ArrayList(subset)); return; } solve(index+1,nums,subset,subsets); subset.add(nums[index]); solve(index+1,nums,subset,subsets); System.out.println("Backtracking!"); subset.remove(subset.size() -1); }
@ayushkushwaha171
@ayushkushwaha171 2 года назад
Damn, i used to be hell scared by these questions earlier. Now these look easy. Thanks to you!
@sadaf_r
@sadaf_r 2 года назад
You are great...aap jo bhi bolte ho sab samjh aata hai bhaiya😅
@PIYUSH-lz1zq
@PIYUSH-lz1zq 2 года назад
Index >nums.size() q nahi hoga ? Q ki last element pe exit nahi marna hai !
@goodquotesforlife4203
@goodquotesforlife4203 Год назад
yes bhaiya understand both question . attendance marked
@mohammadmuzaffarhyder6540
@mohammadmuzaffarhyder6540 2 года назад
thanks bhaiya apka support ka liya,hamarae internal and sem end chalra hai isliya 2 3 lag ma hai magar we are covering up ,thanks alot for the videos
@rahulprasad1432
@rahulprasad1432 2 года назад
Going strong day by day
@prashantbirajdar9271
@prashantbirajdar9271 2 года назад
haa bhaiya smj aye dono questions..🥰😍
@MrDeepanshugarg09
@MrDeepanshugarg09 2 года назад
I don't have words to thank you bhai..
@vakhariyajay2224
@vakhariyajay2224 2 года назад
Thank you very much. You are a genius.
@ritikpatel7918
@ritikpatel7918 2 года назад
Both question are clear bhaiya... Great explanation... Thanks for that...
@mukeshjangid1090
@mukeshjangid1090 2 года назад
Solution in Java class Solution { public List subsets(int[] nums) { List result = new LinkedList(); List output = new LinkedList(); findSubsets(nums, 0, result, output); return result; } private void findSubsets(int[] nums, int index, List result, List output){ if(index==nums.length){ result.add(new LinkedList(output)); return; } //Include output.add(nums[index]); findSubsets(nums, index+1, result, output); //Exclude output.remove(output.size()-1); findSubsets(nums, index+1, result, output); } }
@jaikushwaha1012
@jaikushwaha1012 2 года назад
why u are using linked list in place of array?
@sherebanoburhani8939
@sherebanoburhani8939 2 года назад
Present bhaiya! Watching your lecture 21 today.
@iEntertainmentFunShorts
@iEntertainmentFunShorts 2 года назад
Bhaiya maja aa gya ++ PS : bhaiya yei bateyi muje ek doubt h aapne subset wale problem m backtracking q ni ki after including the element bcoz Mera backtracking ka vode chal rha h or apka bhi ?
@tarunchauhan1025
@tarunchauhan1025 2 года назад
Great and excellent Bhaiya the way u explained . Enjoying to learn..........👌👌💯💯💯💯
@vishabjulka1093
@vishabjulka1093 2 года назад
Thanks bhaiya, this course is really helpful... 🔥🔥
@supersuperhero2449
@supersuperhero2449 Год назад
1st question me, outut bale vector me, only one element, index bala push hona chahiye, phir he 2 elements (1, 2) ek saath kese push ho raha he?
@tayalharsh2026
@tayalharsh2026 7 месяцев назад
mazza agaya ......
@jatingarg1897
@jatingarg1897 2 года назад
Ab samajh aye ye questions. Finally
@aryan5035
@aryan5035 2 года назад
Very well explained. Thank you so much.
@B-NikhilRichhariya
@B-NikhilRichhariya Год назад
bhaiya dono questions samajh m aa gaye !
@gauravpathak3090
@gauravpathak3090 2 года назад
Bhaiya leetcode pe questions to solve ho rhe hai pr optimization nhi ban rhi hai jyadatar TLE hi milta hai
@Jai_Jai_shri_Ram108
@Jai_Jai_shri_Ram108 2 года назад
nice way of teaching
@prakhargupta3949
@prakhargupta3949 Год назад
uda diya ye lecture bhaiya ne
@akshaysingh1211
@akshaysingh1211 2 года назад
Now I'm pro in recursion..thank you
@adarshkumargupta2181
@adarshkumargupta2181 2 года назад
thankyou so much bhaiya by the way vector easy hai use karna baki normal array ke case mai thora jada mehanat hai thora sa jada utna bhi nhi bhot easy code tha
@astroop1528
@astroop1528 Год назад
bhaiya dono question samjh aagye....reach++
@lavishsinghal5769
@lavishsinghal5769 2 года назад
Dono questions samaz aagaye bhaiya