Sach bolu to mera ek dost hai jisne aapke yaha se classes thi java foundation or level ki or mai bhi java krta tha to mujhe usme bhot improvement dekha maine usse pucha ki bhai kha se kra tune tb usne btaya but mere ghr se bhit tha or fee bhi afford nhi kr skta tha mai kyuki maine already ek course le rakha tha but mujhe aapki video dekhni bhi to maine aone dost se sikhna shuru kr diya tha byt ab aapne foundation free kr diya hai to, mai to bhot khus hu. Thank you sir
I've been dreading recursion and all questions related to it everytime I prepare for interviews. I recently started watching these videos and I'm just amazed at how clearly you've managed to explain these concepts. Thank you so much sir!!
awesome explanation.. I am in awe of how in-depth knowledge is provided methodologically in each topic.. must have taken a lot of effort to compile such intelligent videos and present in such simple terms, such that even people like me (thick head) can connect the dots..
This is the C++ code for this question. Upvote or Pin so that C++ coders can also follow vector gss(string s){ if(s.length()==1){ //In the base case length is taken to be 1 instead of 0 so that it doesnt give any segmentation faults vector ans; ans.push_back(""); ans.push_back(s);
return ans; } vectorans2 = gss(s.substr(1)); //Answer returned by passing the substring of the original string vectorresult; int i=0; int j=0; for(i=0;i
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like my efforts, I request a review g.page/Pepcoding/review?rc
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like our efforts, we request a review g.page/Pepcoding/review?rc You can subscribe to our channel here th-cam.com/users/Pepcodingabout?view_as=subscriber
Sir make videos like this one. This video has all the concepts used before doing question and then the explanation of question. Your explanation was so smooth that noone can even forget the explanation after watching video. Make videos like this one, without worrying about the length of video. Absolutely loved it..
Okay beta! I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like our efforts, we request a review - g.page/Pepcoding/review?rc
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like my efforts, I request a review g.page/Pepcoding/review?rc
Thankyou beta! If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms ) Keep learning and keep loving Pepcoding😊
sir this is the first video where it gets little complicated for the one who are learning concept and applying itself(means changing the code to the desired language) like c++
Thankyou beta! I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc
ok , if we have to reduce the space we can declace only 1 arraylist, it will still work just we can calculate its length after the fuction call and we can start a loop from 0 to that size and inside the loop we can write rres.add(ch+rres.get(i)).
Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Thankyou beta! I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
*Code in python* def getSubseq(str) -> list: if len(str) == 0: ss = [] ss.append("") return ss first = str[0] ss = getSubseq(str[1:]) ssres = [] for i in range(len(ss)): ssres.append(first + ss[i]) for i in range(len(ss)): ssres.append("_" + ss[i]) return ssres string = "abc" arr = getSubseq(string) print(arr)
We can also do with the 2 recursive calls as shown using recursive tree. #code def subsequence(s, op): if s == "": res.append(op) return op1 = op + " _ " subsequence(s[1:], op1) op2 = op + s[0] subsequence(s[1:], op2) global res res = [] s = "ABC" subsequence(s, "") print(res)
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem. If you like our efforts, we request a review - g.page/Pepcoding/review?rc
Sir i did the sequence using recursion... getting all the values but not in the order u written with void return import java.util.Scanner; public class rec_15_arr_sequence { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.println("Enter a word"); String str=sc.next(); gss(str,str.length(),str); } public static void gss(String str, int n, String str1) { if(str.equals("")) { return; } String sub=str.substring(0,n); if(str.length()==1) { if(str.charAt(0)==str1.charAt(0)) { str=str1.substring(1); str1=str; System.out.println(str); gss(str,str.length()-1,str1); } } else { System.out.println(sub); gss(sub,n-1,str1); } } } can u please correct it and do it using Arraylist 😊
String ros = str.substring(1);// when this runs for str="c".......ch will be ch=str.charAt(0)=c......and ros=str.substring(1)...str is "c" i.e there is only 0th index and no 1st index in str...then why this line ros=str.subtring(1) is not throwing an index of bounds error?.............I anaylsed and found out that for string str of length n, having index positions 0 to n-1, str.substring(0) to str.substring(n) can be accesssed...this is counter-intuitive to me as as how we are able to access index n, whereas last character of string has index n-1.......does internally for any string, after the last character, there is one more empty character appended at the end by java library?
Sir at 22:23 when you say str.substring(1) then for c alone the 1th index does not exist ,then shouldnt it display INDEX OUT OF BOUND EXCEPTION? Why is the code working then?
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
1 hr laga lekin khudse ban gya, ab confidence aa gya recursion me lagta hai. THANK YOU SIR 🙌🙌🙏🙏 public static ArrayList < String > gss(String str) { if (str.length() == 0) { ArrayList < String > sm = new ArrayList < > (); sm.add(""); return sm; } ArrayList < String > sList = new ArrayList < > (gss(str.substring(1, str.length()))); int x = sList.size(); sList.add((str.charAt(0) + "")); for (int i = 1; i < x; i++) { StringBuilder s = new StringBuilder(sList.get(i)); s.insert(0, str.charAt(0)); sList.add(s.toString()); } return sList; }
Thankyou beta! I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, would you like to review us here - g.page/Pepcoding/review?rc
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
The cookie in this question would be the base case according to me, if you decide on taking substring of length 1 as the base case you'll miss the empty string in the subsequences. TLDR; Call Smart Base Case Normal Call Normal Base Case Smart - Sumeet Malik
Sir, base case mein arraylist mein ek element Jo ki blank hai voh kyu return kiya, agar empty arraylist return karte toh bhi toh result same aata. What was the need to include that blank element in arraylist. Meko samjh aa gya that a blank string has one subsequence which is black(2^0=1) , but sir uss blank element ko na add karna zaroori kyu tha? Empty arraylist return karte toh rres mein loop lag ke vahi toh result aata??!
empty arraylist return karte to neeche loop he nahi chalta. iski jagah arraylist mei 1 element (jo blank hai) wo daal ke return karte hain to neeche kam se kam ek baar loop chalta hai
wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.
Sir I didn't got the difference between the last part of code when adding both space and a in same loop was not accepted but in doing in different loop how it was expected
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
Thankyou beta, I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem. If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )
here's an alternate code for this question public class recursion_intermediate { public static ArrayList res = new ArrayList(); public static ArrayList subseq(String str, int index, String newstr) { if(index==str.length()){ res.add(newstr); return res; } char currchar = str.charAt(index); //for char to be in new string subseq(str,index+1,newstr+currchar); //call for next char including char[index] //for char to not be in new string subseq(str,index+1,newstr); //call for next char without including char[index] return res; } public static void main(String args[]){ String str ="abc"; ArrayList uwu = new ArrayList(subseq(str,0,"")); System.out.println(uwu); } }
Just a realization, sub sequence discussed here is subset of a set. {a,b,c} is a set and we here are trying to list out all the subsets. So for {a,b,c} subsets are {} {a} {b} {c} {a,b} {a,c} {b,c} {a,b,c} this also fits nicely together with the base case where we need to return empty set as it too is the part of the subset collection. Hope this helps people to visualize the problem better.
Sach bolu to mera ek dost hai jisne aapke yaha se classes thi java foundation or level ki or mai bhi java krta tha to mujhe usme bhot improvement dekha maine usse pucha ki bhai kha se kra tune tb usne btaya but mere ghr se bhit tha or fee bhi afford nhi kr skta tha mai kyuki maine already ek course le rakha tha but mujhe aapki video dekhni bhi to maine aone dost se sikhna shuru kr diya tha byt ab aapne foundation free kr diya hai to, mai to bhot khus hu.
Thank you sir
beta, agar help mil rhi hai to subscriber juta de. Webinar kra de college mei?
@@Pepcoding sir ho jayenge subs , aap nhi jante kitne log iske liye ghoom rhe thae idar se udar
dilasa na de bhai. FB, Insta pe share kar do maybe. Class groups mei whatsapp kar de maybe. Help is appreciated.
Sir baki maine apne telegram , whatsapp or jha bhi college group h share kr diya h.
@@Pepcoding Nhi sir sach bolra hu telgram pr, or whatsapp pr college ka group hai waha share kiya h
I've been dreading recursion and all questions related to it everytime I prepare for interviews. I recently started watching these videos and I'm just amazed at how clearly you've managed to explain these concepts. Thank you so much sir!!
You are doing great work. I was part of Nagarro when you were there. It's good to see you grow because you deserve it.
awesome explanation.. I am in awe of how in-depth knowledge is provided methodologically in each topic.. must have taken a lot of effort to compile such intelligent videos and present in such simple terms, such that even people like me (thick head) can connect the dots..
Thankyou beta!
If you like our efforts, will you like to write a review about us here - g.page/Pepcoding/review?rc
Out of the box thinking.... I was doing this the old way of doing this... Thanks to you pepcoding team..
Thanks beta..quora pe likh dena humaare liye review
@@adityasrivastava7956 Sure sir😅
@@kushalappaca5324 Thanks you beti
This is the C++ code for this question. Upvote or Pin so that C++ coders can also follow
vector gss(string s){
if(s.length()==1){ //In the base case length is taken to be 1 instead of 0 so that it doesnt give any segmentation faults
vector ans;
ans.push_back("");
ans.push_back(s);
return ans;
}
vectorans2 = gss(s.substr(1)); //Answer returned by passing the substring of the original string
vectorresult;
int i=0;
int j=0;
for(i=0;i
vector function_1(string temp) {
if (temp.size() == 0) {
return {""};
}
string c = temp.substr(0, 1);
string temp_2 = temp.substr(1, temp.size());
vector ret = function_1(temp_2);
vector output;
for (auto i : ret) {
output.push_back("" + i);
output.push_back(c + i);
}
return output;
}
//better than the above and less confusing
Thank you so much sir.
your approach of:
first make expectations and then fulfill it in recursion is working great.
Best channel for Java coding
Sir ekdum feeling aa gya sir, cant express
As usual, super explanation sir!!
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like my efforts, I request a review
g.page/Pepcoding/review?rc
[ c++ solution with no extra space ]
void print(string inp , string out){
if(inp.size() == 0){
cout
best concept building lectures by:'Prepcoding'.....
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like our efforts, we request a review
g.page/Pepcoding/review?rc
You can subscribe to our channel here
th-cam.com/users/Pepcodingabout?view_as=subscriber
Sir make videos like this one. This video has all the concepts used before doing question and then the explanation of question. Your explanation was so smooth that noone can even forget the explanation after watching video. Make videos like this one, without worrying about the length of video. Absolutely loved it..
Okay beta!
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like our efforts, we request a review - g.page/Pepcoding/review?rc
@@Pepcoding Done Sir
you r the best teacher in the world. understood it crystal clear. Thanks a lot
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like my efforts, I request a review
g.page/Pepcoding/review?rc
Sir, you did proper justice to the explanation. Best explanation sir over whole TH-cam 😍😍🤩🥰
Thankyou beta!
If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )
Keep learning and keep loving Pepcoding😊
@@Pepcoding Absolutely sir..... 🤗🤗
Good Guy, Good Explanation, Good Vibes! Thanks Brother.
Thanks!
Very nice explanation sir…thank you very very much
Watched on 18 October, 2021 - Thanks for the video.
It's an outstanding explanation sir thanks a lot for providing such a quality content
Man with zero haters!!
sir this is the first video where it gets little complicated for the one who are learning concept and applying itself(means changing the code to the desired language) like c++
Dil ki baat kehe di apne to 😄🤣
After learning vector.... I think it won't get much difficult😣 😄
@@sayanmaitra11 yes
Language doesn't matter explanation is op
If u know basics of any language and understand the concept I bet u will do it bro 🤜
Awesome Explation Sir
Superb 😇😇😇thank you sooo much sir!
Most welcome 😊
Bahut bhadiya sir. Dhanyavaad!
Thankyou beta!
I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, will you like to review us here - g.page/Pepcoding/review?rc
ok , if we have to reduce the space we can declace only 1 arraylist, it will still work just we can calculate its length after the fuction call and we can start a loop from 0 to that size and inside the loop we can write rres.add(ch+rres.get(i)).
Very nice explanation sir
Wonderful explanation Sir!
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
brilliantly explained sir thank you :)
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Very well explanation.
*Code in python*
def getSubseq(str) -> list:
if len(str) == 0:
ss = []
ss.append("")
return ss
first = str[0]
ss = getSubseq(str[1:])
ssres = []
for i in range(len(ss)):
ssres.append(first + ss[i])
for i in range(len(ss)):
ssres.append("_" + ss[i])
return ssres
string = "abc"
arr = getSubseq(string)
print(arr)
great explanation
Java code :
static ArrayList powerSet(String s)
{
if(s.length() == 0) {
ArrayList list = new ArrayList();
list.add("");
return list;
}
char ch = s.charAt(0);
String smallInput = s.substring(1);
ArrayList smallInputResult = powerSet(smallInput);
ArrayList result = new ArrayList();
for( String res : smallInputResult ) {
result.add(res);
result.add( ch + res);
}
return result;
}
We can also do with the 2 recursive calls as shown using recursive tree.
#code
def subsequence(s, op):
if s == "":
res.append(op)
return
op1 = op + " _ "
subsequence(s[1:], op1)
op2 = op + s[0]
subsequence(s[1:], op2)
global res
res = []
s = "ABC"
subsequence(s, "")
print(res)
best explanation
great
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like our efforts, we request a review - g.page/Pepcoding/review?rc
Sir can we use Sc. nextLine() for string input in place of Sc. next() ?
Sir Can you please explain why did you need 3rd arrayList. Can we do it without 3rd arrayList.
awesome explanation!!!!
Sir i did the sequence using recursion...
getting all the values but not in the order u written with void return
import java.util.Scanner;
public class rec_15_arr_sequence
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a word");
String str=sc.next();
gss(str,str.length(),str);
}
public static void gss(String str, int n, String str1)
{
if(str.equals(""))
{
return;
}
String sub=str.substring(0,n);
if(str.length()==1)
{
if(str.charAt(0)==str1.charAt(0))
{
str=str1.substring(1);
str1=str;
System.out.println(str);
gss(str,str.length()-1,str1);
}
}
else
{
System.out.println(sub);
gss(sub,n-1,str1);
}
}
}
can u please correct it and do it using Arraylist 😊
Sir, can you explain how code is working in for loop at recursive level means what is getting in for loop at stack like first c, then bc, then abc
sir pepcoding ki site ko kya ha chal kyo nahi rhi?
String ros = str.substring(1);// when this runs for str="c".......ch will be ch=str.charAt(0)=c......and ros=str.substring(1)...str is "c" i.e there is only 0th index and no 1st index in str...then why this line ros=str.subtring(1) is not throwing an index of bounds error?.............I anaylsed and found out that for string str of length n, having index positions 0 to n-1, str.substring(0) to str.substring(n) can be accesssed...this is counter-intuitive to me as as how we are able to access index n, whereas last character of string has index n-1.......does internally for any string, after the last character, there is one more empty character appended at the end by java library?
Sir at 22:23 when you say str.substring(1) then for c alone the 1th index does not exist ,then shouldnt it display INDEX OUT OF BOUND EXCEPTION? Why is the code working then?
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
You can pass the string length in substring method, anything beyond that is indexoutofbound error correct me if I’m wrong
Thank you very much sir
Most welcome!! keep watching the videos
Thanks 😊
sir cpp me bhi content daliye please...
what is the time and space complexity of this solution
1 hr laga lekin khudse ban gya, ab confidence aa gya recursion me lagta hai.
THANK YOU SIR 🙌🙌🙏🙏
public static ArrayList < String > gss(String str) {
if (str.length() == 0) {
ArrayList < String > sm = new ArrayList < > ();
sm.add("");
return sm;
}
ArrayList < String > sList = new ArrayList < > (gss(str.substring(1, str.length())));
int x = sList.size();
sList.add((str.charAt(0) + ""));
for (int i = 1; i < x; i++) {
StringBuilder s = new StringBuilder(sList.get(i));
s.insert(0, str.charAt(0));
sList.add(s.toString());
}
return sList;
}
Thankyou beta!
I am glad you liked it. I also hope that you are watching till the end and trying to understand the what, how, and especially why of the problem. If you like our efforts, would you like to review us here - g.page/Pepcoding/review?rc
how to handle below case as per this code :
Input: digits = ""
Output: []
as it will return output as [""] not []
@Pepcoding sir can you tell the time and space complexity of this ques, please?
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
please summet sir level 2 bhi ap banado plz
The cookie in this question would be the base case according to me, if you decide on taking substring of length 1 as the base case you'll miss the empty string in the subsequences.
TLDR;
Call Smart Base Case Normal
Call Normal Base Case Smart
- Sumeet Malik
doubt shoubt ke liye yahi content nados.pepcoding.com pe consume karein
Sir, base case mein arraylist mein ek element Jo ki blank hai voh kyu return kiya, agar empty arraylist return karte toh bhi toh result same aata. What was the need to include that blank element in arraylist. Meko samjh aa gya that a blank string has one subsequence which is black(2^0=1) , but sir uss blank element ko na add karna zaroori kyu tha? Empty arraylist return karte toh rres mein loop lag ke vahi toh result aata??!
empty arraylist return karte to neeche loop he nahi chalta. iski jagah arraylist mei 1 element (jo blank hai) wo daal ke return karte hain to neeche kam se kam ek baar loop chalta hai
@@Pepcoding okay sir samjh aa gya😄. Thankyou
thanks sir, your content is great, a recommendation is if you can make the content in english it could reach wider audience
Hanji beta, jaldi he bnayege content english main bhi but it'll take time.
can anyone make me understand that loop part like how do we apply loop while doing it in c++
legendary
HE IS NOT A HUMAN , HE IS SOMETHING OUT OF THIS WORLD.
wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.
God 😍😍
tnq Sir
Sir I didn't got the difference between the last part of code when adding both space and a in same loop was not accepted but in doing in different loop how it was expected
Beta, I regret to inform you that, I won't be able to answer/solve the personal doubts of each and every student over here. For clearing your doubts, you can join our community on telegram - t.me/pepcoding.
You nice❤ but you are very underated😔
Thankyou beta,
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/How-do-I-start-learning-or-strengthen-my-knowledge-of-data-structures-and-algorithms )
Sir apka content bacho tak nahi ja pa raha h
here's an alternate code for this question
public class recursion_intermediate {
public static ArrayList res = new ArrayList();
public static ArrayList subseq(String str, int index, String newstr) {
if(index==str.length()){
res.add(newstr);
return res;
}
char currchar = str.charAt(index);
//for char to be in new string
subseq(str,index+1,newstr+currchar); //call for next char including char[index]
//for char to not be in new string
subseq(str,index+1,newstr); //call for next char without including char[index]
return res;
}
public static void main(String args[]){
String str ="abc";
ArrayList uwu = new ArrayList(subseq(str,0,""));
System.out.println(uwu);
}
}
For better experience and well organised content visit - nados.io
You can also post your doubts on community section of NADOS.
Just a realization, sub sequence discussed here is subset of a set.
{a,b,c} is a set and we here are trying to list out all the subsets. So for {a,b,c} subsets are
{}
{a}
{b}
{c}
{a,b}
{a,c}
{b,c}
{a,b,c}
this also fits nicely together with the base case where we need to return empty set as it too is the part of the subset collection. Hope this helps people to visualize the problem better.
Wow❤️
Keep watching and keep learning😊
sir, for loop ka declaration samaj nai aya.
if anyone can explain??
Strings, StringBuilder and ArrayList wale lecture mei jake ek baar ArrayList ka demo dekhie.
String ka use base ke liye huwa hai na i mean string jeb 0 length ki hoti hai to uske liye hai
Yes
🤟🏻🙌🏻🔥
For much better experience visit on nados.pepcoding.com
Don't forget to follow us on Instagram instagram.com/pepcoding/
9:50
how to do multiple lines comment at a time can anypne please help me in this
step1- select multiple line
step2-ctrl+/
it will do multiple comment at a time
by using language: /*to be commented*/
by using keyboard: Select the content and press CTRL + /.
26:48 sirji ye jo awaaz aa rahi hai that is causing problem in concentration ...please nullify it sir
okay beta.
👍
Hello chachu your Aryan
Hello betu. Chachu loves Aryan
I love you too chachu your Aryan
brute force god
Respect++;
sir cpp ke liye recursion banaiye plzz
🙏
JavaScript ???????? Anyone ??????/
code in c++
vector gss(string s){
// write your code here
if(s.size()==0){
vector base;
base.push_back("");
return base;
}
char ch = s[0];
string ros = s.substr(1);
vector retu = gss(ros);
vector result;
for(int i=0;i s;
vector ans = gss(s);
int cnt = 0;
cout