Count Subsequences of form A^i B^j C^k | Count A+ B+ C+ Subsequences Dynamic Programming
Vložit
- čas přidán 2. 08. 2020
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we explain about A+B+C+ subsequences and state the problem where we are required to count and print the number of such sequences formed for a given string. In this problem,
1. You are given a string str.
2. You are required to calculate and print the count of subsequences of the nature a+b+c+.
For abbc - there are 3 subsequences. abc, abc, abbc
For abcabc - there are 7 subsequences. abc, abc, abbc, aabc, abcc, abc, abc.
Tu submit this question, click here: www.pepcoding.com/resources/o...
For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
#pepcoding #java #programming
Have a look at our result: www.pepcoding.com/placements
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
8:52 Men will be Men 🔥
Whoa! All this for free! Respect for you, still people will complain why you are selling courses!
Haha Keep learning, Keep growing and keep loving Pepcoding!😊
Khub valo
this man deserve best teacher award for my opinion
legendary Thank You Sir.
sir whenever i stuck in hard question in starting i try many chaannels but after come to ur channel i think for hard questions u have only one in youtube community who explained in easiest way
Your videos are really helpful sir.. Thankyou
Dual nature video.. we can enjoy listening to music while coding 😛😛😜
Glad you enjoy it!
thanks for the video
literally dp kya kamal ki chiz hai... sidhe 2^n se n
Sir A genuine feed back.
I have watched almost all your videos and I feel this dual concept is much better, and it's very easy to understand this way.
I have even watched your previous video where you were explaining the question and algo to a student, it was very natural
Thanks for sharing
bro can u tell me ,iske baad konsi playlist dheku LEVEL UP/RECURSION AND BACKTRACKING/DP?? CAN U TELL ME THE ORDER ?,,,I WANT TO LEARN DP & RECURSION
student ni h , wife h sir ki
@@mayankverma8520 DSA - Level 1 playlist order me dekh lo
Sir want to salute you for such dedicated work
Keep it up sir , you are great your way to approach the problem is fabulous .
Thanks a ton and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Sir No doubt aap bohot accha pdhate hai, par dynammic programming m thodi problems hai,sir you must have watched aditya vermas dp playlist,so please dont take this otherwise but sir agr recursive and memoized krke agr tabulation wala method dekhe toh jada easy hota hai in smajhne mai,bcz sir aise tabulation wale tareeke direct click nahi krte.
Sir, can't get a better explanation than this!👏
Amazing!!
Thanks a lot. It would be great if you could share the channel on your FB and Linkedin.
On leetcode there is regular expression matching and wildcard matching question, please make a video on them if possible ,
It would be great if you explain it .
Noted
summet sir........kya directly tabulation se sochna theek hai ya phle recursion se kiya jaye thoda fir tabulation ?????
aur agr tabulation se sochna hai starting se to sir abhi bilkul strike nhi krta ki meaning kya banega help me out please @Pepcoding
i have same doubt.
@@nirajgusain4597 yes
you are best teacher that i have ever seen
Huge respect for Sumit sir
Great explaination sir. Pls make video on 🥚 drop problem. Thanks
Sure I will
Why aren't be trying to find all the subsequences of aabbcc?? I think this may approach may work
Hi Sumit sir,
Hope this msg finds you well!.
I had one doubt in solving one sub sequence i.e. abbac. could you please explain if it's valid test case or not for this problem.
Thanks
nice video sir ji majha aa rha h
Keep learning, Keep growing and keep loving Pepcoding!😊
Sir, Ye wala question itna ache se smjh hi aaya..Ho sake to thoda better way m vaps smjhane ka try krna
hanji isko kra dunga dobara.
Sir ne shi se kraya hai permutaion nhi ker paye hoge ek bar socho meditation kero aa jayega
If it is possible please make video on robin karp algorithm or stribg matching algorithm ..please
ow sir ji first i solved this question by myself ..
and i didn't consider character as different ..
for ex:
abcabc .
i considered both a as same ..
and after this .. i solved this using 1d dp and i got the ans 8 for above example .
thanks sir ji for your great explanation .
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
sir...isme jo formula hai ... 2a+1,2b+a,2c+b ye kaise aya??
solving this question without seeing answer is too tough, i tried it for 1 day
Jab se Ma'am aai h videos m complexity badh gaya h
sir can you please share video in top-down approach also . it is more intuitive
Alright
Thank you very much sir.
Just one doubt eg "abca" the output should be aabc, abc, abc .
But from above table we will get output as 1 ?
beta order nahi badal sakte, aabc galat hai. a ko aage nahi la sakte
@@Pepcoding Thank very much sir for your reply , Now I got the question right.
Sir, is mein pattern (ya formula) dhundhna difficult laga. Aap kaise dhundte ho, any special points to keep in mind, kyuki jab table dekh kar bana raha tha to pattern bohot random laga, like a ka formula a' pe pata chala jo b aur c k baad h.
beta mai bhot originally nahi soch pata to jab mai ek type ke kaafi question kar chuka hota hun to dekh pata hun. ye mujhe usi group ka question lga include exclude jaisa. Aur bhot baar, mai question solve nahi kar pata, solution dekh kar samajh pata hun. By practicing a lot we can increase our probability of solving (we may encounter a question already done or because of improved pattern recognition ability we may be able to see solutions in new problems - people also call this intuition), but we can never eliminate luck out of the equation
In this question, do we assume that the input is also always in a+b+c form?? if no than lets say the input is "abca". So according to me there are 2 subsequences possible for this input that is abc and aabc. But the output will be 1 only. Do correct me if I am wrong. :)
"aabc" is not a subsequence of "abca". Subsequences can include or not include an element, but there cannot be a change in the position of the elements. For "abca" the there are 16 subsequences out of which "abc" is the only one that will be considered here.
correct answer
Subsequence means relative order must be same, Not necessary to be continous.
@@riyasinghal9869 tq, I was stuck over here.
Sir plz remake this vidio when u get time ! And explain question in detail. I dont understand question in this
By watching again , i understand it ver clearly
@@45_ritiksharma32 🤣🤣
Sir in videos mai ques aur answer video alag islea nhi hai na kyuki ye topic soln dekh kar smajna hai??
nhi nhi
Hehe
JAVA CODE :
import java.util.Scanner;
public class CountSubSequnceConditional {
public static void main(String[] args) {
Scanner scn= new Scanner(System.in);
String str=scn.nextLine();
int a=0,ab=0,abc=0;
for(int i=0;i
sir apne jitne bhi is type ke question krwaye h unka memorisation phle smja diya kro kyuki dp ki jitne bhi question krte h usme phle memorisation sochne ke baad hi tabulation lgate h ...to tabulation sochna thoda aasan hojata h
ok ji.
What if, we want to count only unique subsequence. As always great video Sumit sir.
By my heart u r best teacher till my collage journey and wants to learn more from u , keep uploading sir ,
Thank you, I will
sir iska intuition poori dp ki playlist krne ke baad aah jaega na?
sir you took a=0,ab=0 & abc=0 , can we take a=1,ab=0 & abc=0?? because it has to start with "a" anyways..
sir aapne string kaise assume karli , a b c a' b' c'. iske alawa bhi koi assume kar sakte hain kya.
Hanji
smjh ni aa rha kya ho rha
Sir, Identify kaise kare ki 2D dp se solve karna he ya 1D dp se koi problem ko? Thanks.
beta practice krtee rhiee jb dp kee 80 questions kr logge tbb jakee soch paooe
Bro 2 D pe tab kerte hai jeb tumhe repeted nhi chahiye hota hai as tumhre pass 2 aur 6 hai tumhe 8 bnana hai tum 2222 kerke nhi bnana chahte ho to to tum 2 d array use kero kyoki tum hmesa ek piche call keroge jisme tum apna se pahla wala ka effect genrate keroge dp me
sir , how can we identify that this is a dp question ? Can this question be solved recursively ?
all dp questions can be solved by recursion
Nahi sir issme mazza ni aaya 2-3 baar dekh li phir bhi samjh ni aaya !!!! sir isko redo kro ya baada test case lekar samjhao
theik beta. Point noted, will redo it.
@@Pepcoding that's the spirit of a true teacher!!! keep growing
Bhai tera piche k topics clear nhi honge,aur video baar baar dekhne se acha pen copy jyada chla
@@anjneykumarsingh4461 baat to shi hai teri but mazza ni aaya video dekh ke.... Baaki sabka apna apna perspective hota hai
Ha mtlb maths jaisa soln videos dekhoge toh problem solving..... K hojayega
sir shouldn’t be it substring rather than subsequence because we are concluding answers based on the order of the string given
because if string is "abcabc" it generates 7 while if it is "aabbcc" it gives 27
It is not a substring because a substring needs to be continuous. Here, even though the relative order of the characters is maintained, it can be discontinuous. For example, consider the string aabbcc. Here, abc is a subsequence because the order is maintained, but it is not a substring because you don't see abc in any part of the string, without losing continuity. Hope I'm making sense.
sir pls also provide code in description box.
Visit our portal : pepcoding.com
You can see all the codes there
sir mujhe bhi quesiton clear nahi hua, plz redo if possible
ye possible nhi hai ji
Sir iska recursion se krwa doh , tree vgrah bnwa k
xD
int solve(string &s,int idx ,int a,int b,int c)
{
if(idx==s.size())
{
if(a!=0 && b!=0 && c!=0)
return 1;
else
return 0;
}
if(s[idx]=='a' && b==0 && c==0)
{
return solve(s,idx+1,a+1,b,c) + solve(s,idx+1,a,b,c);
}
else if(s[idx]=='b' && a!=0 && c==0)
{
return solve(s,idx+1,a,b+1,c) + solve(s,idx+1,a,b,c);
}
else if(s[idx]=='c' && a!=0 && b!=0)
{
return solve(s,idx+1,a,b,c+1) + solve(s,idx+1,a,b,c);
}
else
return solve(s,idx+1,a,b,c);
}
int fun(string &s) {
//code here
int res = solve(s,0,0,0,0);
return res;
}
@@pathikritchanda62 can you explain your code,it is bit hard to understand the code only
Sir samajh nahi aaya... :(
Kya samjhaya hai sir maja aa gya :D
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
@@Pepcoding done sir 😄
Ye to simple array ka question lag raha , recursion dp ka to feel he nahi aaya
@15:10 pe kuch cut hua aisa lga ..
aabbcc part nhi hoga?
You can refer to nados.pepcoding.com for solving all your doubts and queries.
aabbcc substring nahi hai. Permutation hai
substrings hmesha order me aati hai
Kisine recursion se kiya ho to please code bhej do
in example abcabc : why aabbcc is not included in ans.
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.
@@Pepcoding let me answer this .... take example of abc ...ac to ek subsequence hai but acb galat hai ....
same here aa'b'c' is ok (beech wale bc nhi aye ) but aa'bc is not ok similliarly aa'bb'cc' is not ok
i hope this answer help you out
Sir you are indian Richard Feynman!!!
Arey nahi. Itna bda nahi hun mai.
To all those people who are not able to understand the logic. Trust me. Sit with a pen and paper and solve with sumeet sir. Give him your 15 minutes. Watch the video even if you are not getting it. At the end of the video you will surely get the logic once you have seen the explanation and then the code.
kya boring explanation hai 😒