Count Subsequences of form A^i B^j C^k | Count A+ B+ C+ Subsequences Dynamic Programming

Sdílet
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

Komentáře • 116

  • @nishantingle1438
    @nishantingle1438 Před 2 lety +9

    8:52 Men will be Men 🔥

  • @palashrathore6277
    @palashrathore6277 Před 3 lety +24

    Whoa! All this for free! Respect for you, still people will complain why you are selling courses!

    • @Pepcoding
      @Pepcoding  Před 3 lety +9

      Haha Keep learning, Keep growing and keep loving Pepcoding!😊

  • @souviknandi9298
    @souviknandi9298 Před 2 lety

    Khub valo

  • @freelygaming696
    @freelygaming696 Před 2 lety +6

    this man deserve best teacher award for my opinion

  • @SonuKhan-mp2yn
    @SonuKhan-mp2yn Před rokem

    legendary Thank You Sir.

  • @anubhavgarg7056
    @anubhavgarg7056 Před rokem

    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

  • @padhisandeep96
    @padhisandeep96 Před 3 lety

    Your videos are really helpful sir.. Thankyou

  • @QueenCoder
    @QueenCoder Před 4 lety +10

    Dual nature video.. we can enjoy listening to music while coding 😛😛😜

  • @AshishGusain17
    @AshishGusain17 Před 2 lety

    thanks for the video

  • @AKASHKUMAR-li7li
    @AKASHKUMAR-li7li Před 12 dny

    literally dp kya kamal ki chiz hai... sidhe 2^n se n

  • @VikashTiwary
    @VikashTiwary Před 4 lety +26

    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

    • @Pepcoding
      @Pepcoding  Před 4 lety +2

      Thanks for sharing

    • @mayankverma8520
      @mayankverma8520 Před 3 lety +1

      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

    • @wildkingrights7706
      @wildkingrights7706 Před 2 lety +1

      student ni h , wife h sir ki

    • @jagritijain6874
      @jagritijain6874 Před rokem

      @@mayankverma8520 DSA - Level 1 playlist order me dekh lo

  • @naveendhaked9918
    @naveendhaked9918 Před 2 lety

    Sir want to salute you for such dedicated work

  • @suryasingh6037
    @suryasingh6037 Před 3 lety +2

    Keep it up sir , you are great your way to approach the problem is fabulous .

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      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 )

  • @aayushraj7896
    @aayushraj7896 Před 3 lety +6

    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.

  • @kritikapandey8205
    @kritikapandey8205 Před 2 lety

    Sir, can't get a better explanation than this!👏

  • @hemantsingh-zo3iw
    @hemantsingh-zo3iw Před 4 lety

    Amazing!!

    • @Pepcoding
      @Pepcoding  Před 4 lety

      Thanks a lot. It would be great if you could share the channel on your FB and Linkedin.

  • @vyomchandragallani3645
    @vyomchandragallani3645 Před 4 lety +12

    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 .

  • @anubhavgupta4412
    @anubhavgupta4412 Před 3 lety +10

    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

  • @nischayrawat682
    @nischayrawat682 Před 3 lety

    you are best teacher that i have ever seen

  • @AyushKumar-rh1vy
    @AyushKumar-rh1vy Před 2 lety

    Huge respect for Sumit sir

  • @rahulbhatia3075
    @rahulbhatia3075 Před 4 lety +4

    Great explaination sir. Pls make video on 🥚 drop problem. Thanks

  • @shubhamupadhyay9308
    @shubhamupadhyay9308 Před 2 lety

    Why aren't be trying to find all the subsequences of aabbcc?? I think this may approach may work

  • @user-yr8wy4jq5l
    @user-yr8wy4jq5l Před 8 měsíci

    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

  • @pranshulkharniwal8146
    @pranshulkharniwal8146 Před 3 lety

    nice video sir ji majha aa rha h

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Keep learning, Keep growing and keep loving Pepcoding!😊

  • @agamjain8976
    @agamjain8976 Před 3 lety +5

    Sir, Ye wala question itna ache se smjh hi aaya..Ho sake to thoda better way m vaps smjhane ka try krna

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      hanji isko kra dunga dobara.

    • @SCRIPTSAG
      @SCRIPTSAG Před 3 lety +1

      Sir ne shi se kraya hai permutaion nhi ker paye hoge ek bar socho meditation kero aa jayega

  • @pasitopasito1967
    @pasitopasito1967 Před 3 lety

    If it is possible please make video on robin karp algorithm or stribg matching algorithm ..please

  • @AKASH-sw9bs
    @AKASH-sw9bs Před 3 lety +3

    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 .

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      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

  • @youthcoder9893
    @youthcoder9893 Před 2 lety +1

    sir...isme jo formula hai ... 2a+1,2b+a,2c+b ye kaise aya??

  • @ArcGaming07YT
    @ArcGaming07YT Před rokem

    solving this question without seeing answer is too tough, i tried it for 1 day

  • @factsstats3959
    @factsstats3959 Před rokem

    Jab se Ma'am aai h videos m complexity badh gaya h

  • @rishiagrawal8176
    @rishiagrawal8176 Před 3 lety +2

    sir can you please share video in top-down approach also . it is more intuitive

  • @ntesla5
    @ntesla5 Před 3 lety +1

    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 ?

    • @Pepcoding
      @Pepcoding  Před 3 lety +5

      beta order nahi badal sakte, aabc galat hai. a ko aage nahi la sakte

    • @ntesla5
      @ntesla5 Před 3 lety

      @@Pepcoding Thank very much sir for your reply , Now I got the question right.

  • @rajivsahu983
    @rajivsahu983 Před 3 lety +1

    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.

    • @Pepcoding
      @Pepcoding  Před 3 lety +19

      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

  • @shreyanshdeep2171
    @shreyanshdeep2171 Před 3 lety +1

    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. :)

    • @riyasinghal9869
      @riyasinghal9869 Před 3 lety +6

      "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.

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      correct answer

    • @lovleshbhatt7797
      @lovleshbhatt7797 Před 3 lety +1

      Subsequence means relative order must be same, Not necessary to be continous.

    • @theuntoldtree
      @theuntoldtree Před 2 lety

      ​@@riyasinghal9869 tq, I was stuck over here.

  • @45_ritiksharma32
    @45_ritiksharma32 Před 3 lety +3

    Sir plz remake this vidio when u get time ! And explain question in detail. I dont understand question in this

  • @037_sayedramishali7
    @037_sayedramishali7 Před 3 lety +2

    Sir in videos mai ques aur answer video alag islea nhi hai na kyuki ye topic soln dekh kar smajna hai??

  • @rkalpeshk
    @rkalpeshk Před 3 lety +2

    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

  • @abhinavgupta3913
    @abhinavgupta3913 Před 3 lety +1

    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

  • @prashantupadhya9568
    @prashantupadhya9568 Před 2 lety

    What if, we want to count only unique subsequence. As always great video Sumit sir.

  • @mohitkumar-4712
    @mohitkumar-4712 Před 3 lety +1

    By my heart u r best teacher till my collage journey and wants to learn more from u , keep uploading sir ,

  • @mickyman753
    @mickyman753 Před 3 lety +1

    sir iska intuition poori dp ki playlist krne ke baad aah jaega na?

  • @muskanagarwal8810
    @muskanagarwal8810 Před 3 lety

    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..

  • @amandixit3555
    @amandixit3555 Před 3 lety

    sir aapne string kaise assume karli , a b c a' b' c'. iske alawa bhi koi assume kar sakte hain kya.

  • @shubhamkhuntia2412
    @shubhamkhuntia2412 Před 2 lety

    smjh ni aa rha kya ho rha

  • @GauravSingh-bo1ys
    @GauravSingh-bo1ys Před 3 lety

    Sir, Identify kaise kare ki 2D dp se solve karna he ya 1D dp se koi problem ko? Thanks.

    • @Pepcoding
      @Pepcoding  Před 3 lety +3

      beta practice krtee rhiee jb dp kee 80 questions kr logge tbb jakee soch paooe

    • @SCRIPTSAG
      @SCRIPTSAG Před 3 lety +2

      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

  • @sasikiran2450
    @sasikiran2450 Před 3 lety

    sir , how can we identify that this is a dp question ? Can this question be solved recursively ?

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      all dp questions can be solved by recursion

  • @Elon-musk-007
    @Elon-musk-007 Před 3 lety +5

    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

    • @Pepcoding
      @Pepcoding  Před 3 lety +2

      theik beta. Point noted, will redo it.

    • @Elon-musk-007
      @Elon-musk-007 Před 3 lety

      @@Pepcoding that's the spirit of a true teacher!!! keep growing

    • @anjneykumarsingh4461
      @anjneykumarsingh4461 Před 3 lety +5

      Bhai tera piche k topics clear nhi honge,aur video baar baar dekhne se acha pen copy jyada chla

    • @Elon-musk-007
      @Elon-musk-007 Před 3 lety +2

      @@anjneykumarsingh4461 baat to shi hai teri but mazza ni aaya video dekh ke.... Baaki sabka apna apna perspective hota hai

    • @anjneykumarsingh4461
      @anjneykumarsingh4461 Před 3 lety +1

      Ha mtlb maths jaisa soln videos dekhoge toh problem solving..... K hojayega

  • @AbhishekJain-ke3lr
    @AbhishekJain-ke3lr Před 2 lety

    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

    • @akashtn6682
      @akashtn6682 Před 2 lety +3

      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.

  • @sahilnegi2789
    @sahilnegi2789 Před 3 lety

    sir pls also provide code in description box.

    • @Pepcoding
      @Pepcoding  Před 3 lety

      Visit our portal : pepcoding.com
      You can see all the codes there

  • @ShivamKumar-jp2mj
    @ShivamKumar-jp2mj Před 3 lety +1

    sir mujhe bhi quesiton clear nahi hua, plz redo if possible

  • @manavmalhotra8513
    @manavmalhotra8513 Před 3 lety +2

    Sir iska recursion se krwa doh , tree vgrah bnwa k
    xD

    • @pathikritchanda62
      @pathikritchanda62 Před 3 lety +1

      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;
      }

    • @loserfruit9663
      @loserfruit9663 Před 3 lety

      @@pathikritchanda62 can you explain your code,it is bit hard to understand the code only

  • @manjugoswami7063
    @manjugoswami7063 Před 3 lety +1

    Sir samajh nahi aaya... :(

  • @priyanshukhullar5836
    @priyanshukhullar5836 Před 3 lety +1

    Kya samjhaya hai sir maja aa gya :D

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      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

    • @priyanshukhullar5836
      @priyanshukhullar5836 Před 3 lety

      @@Pepcoding done sir 😄

  • @loserfruit9663
    @loserfruit9663 Před 3 lety

    Ye to simple array ka question lag raha , recursion dp ka to feel he nahi aaya

  • @ketanmps2817
    @ketanmps2817 Před 2 lety

    @15:10 pe kuch cut hua aisa lga ..

  • @guy_is_2_shy_to_talk_to_girl

    aabbcc part nhi hoga?

    • @Pepcoding
      @Pepcoding  Před 2 lety +2

      You can refer to nados.pepcoding.com for solving all your doubts and queries.

    • @kashba
      @kashba Před 2 lety

      aabbcc substring nahi hai. Permutation hai
      substrings hmesha order me aati hai

  • @user-dc2ux7el2i
    @user-dc2ux7el2i Před 2 lety

    Kisine recursion se kiya ho to please code bhej do

  • @namanaggarwal1535
    @namanaggarwal1535 Před 3 lety +1

    in example abcabc : why aabbcc is not included in ans.

    • @Pepcoding
      @Pepcoding  Před 3 lety

      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.

    • @anubhavgupta4412
      @anubhavgupta4412 Před 3 lety +2

      @@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

  • @lifecodesher5818
    @lifecodesher5818 Před 3 lety +2

    Sir you are indian Richard Feynman!!!

    • @Pepcoding
      @Pepcoding  Před 3 lety +1

      Arey nahi. Itna bda nahi hun mai.

  • @aakashyadav6228
    @aakashyadav6228 Před 3 lety +1

    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.

  • @davinderkumar2000
    @davinderkumar2000 Před 2 lety

    kya boring explanation hai 😒