Longest Common Subsequence Dynamic Programming | Explanation with Code

Поділитися
Вставка
  • Опубліковано 14 вер 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 discuss the Longest Common Subsequence problem using dynamic programming. In this problem,
    1. You are given a string str1.
    2. You are given another string str2.
    3. You are required to print the length of longest common subsequence of two strings.
    To attempt and submit this question, click here: www.pepcoding.com/resources/d...
    For a better experience and more exercises, VISIT: www.pepcoding.com/resources/o...
    #dp #lcs #dynamicprogramming
    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

КОМЕНТАРІ • 109

  • @neerajbhatia2008
    @neerajbhatia2008 2 роки тому +19

    Sumeet Sir, Just Wow. I have not seen anyone explaining in such great length on the why of the solution to this problem. You are taking India's IT generation to next level and future is not far where lot many inventions and enterpreneurs can be foreseen using this type of education. Dil se Dhanyawaad, great wishes, happiness, peaceful life to you. thank you so much.

    • @Pepcoding
      @Pepcoding  2 роки тому +2

      pleasure is all mine.
      and for better experience, visit nados.io, where you will get well curated content and career opportunities

  • @micklemoon
    @micklemoon Рік тому +1

    I saw another video of this problem of another guy where he started with the table that this video reached after 25 minutes of explanation. In that video, I understood nothing how the table was filled while in this one I did not need to watch further and could fill the table myself. Great explanation, totally worth were the 25 minutes.

  • @tushar207
    @tushar207 2 роки тому

    What an explanation! Nobody explains the algo how it is made just provides them so that we can mug it. Perfect explanation thanks a ton

  • @madIndianHindu
    @madIndianHindu 2 роки тому

    Great Explanation, I can bet that no one could explain this, better than you , after getting your explanation i never needed to see code , saved this for future reference, thanks Sumeet sir for such a wonderful video .

  • @SonuKhan-mp2yn
    @SonuKhan-mp2yn Рік тому

    No words to appreciate, just amazing Thank you very much

  • @deeksha6514
    @deeksha6514 3 роки тому +12

    Thanks a lot sir for explaining the problem in this much depth.This is the best explanation on LCS.

  • @iamredheart22
    @iamredheart22 3 роки тому +8

    The best explanation on LCS. Thanks a lot.

    • @Pepcoding
      @Pepcoding  3 роки тому

      Glad to know that you liked the content and thank you for appreciating. 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 )

  • @animeshkumarchoudhary6324
    @animeshkumarchoudhary6324 2 роки тому

    This guy is explaining at another level

  • @adityatiwari1022
    @adityatiwari1022 2 роки тому

    Sir aap agar developer hote toh abhi mast bhar kahi PM rehte . But you chose teaching! Hats off

  • @vivekgupta_3085
    @vivekgupta_3085 5 місяців тому

    if there is any video of pepcoding of any question then it is best

  • @piyushsaxena6243
    @piyushsaxena6243 2 роки тому

    you are the beest sir
    such an amazing explanation
    keep making such videos sir

  • @sunilg8839
    @sunilg8839 2 роки тому +1

    One of the best explanations on LCS.

    • @Pepcoding
      @Pepcoding  2 роки тому

      Glad you love the explanation, for better experience and well curated content sign up on nados.io and start learning.

  • @SauvikRoy
    @SauvikRoy 2 роки тому

    Side pe samjhane wala idea mast tha! ☺️
    Enjoy your explaining! Thanks a lot!

  • @abhayshekhawat8391
    @abhayshekhawat8391 2 роки тому +1

    sir your are legend no words every word fall short for you just love you:)

    • @Pepcoding
      @Pepcoding  2 роки тому

      Glad to know, that you love Team Pepcoding, for better experience and precisely arranged videos.
      Visit - nados.pepcoding.com and sign up to NADOS.
      Don't forget to follow us on Instagram instagram.com/pepcoding/

  • @adarshdubey1784
    @adarshdubey1784 3 роки тому +2

    i don't know why this channel is so underrated .....

    • @Pepcoding
      @Pepcoding  3 роки тому

      keep motivating, keep learning and keep loving Pepcoding😊

  • @rajeev2127
    @rajeev2127 3 роки тому +7

    Sir itni mathematics ke wajah se kaafi confusion hogya h aur confidence low ho rha h.. like how can we come up with this deep maths behind a question?
    I think sir yeh question ke liye pehle recursive solution fir wahan se DP ka solution wala explanation jyaada sahi rehta..

    • @003abhinashkumarjha8
      @003abhinashkumarjha8 2 роки тому +1

      i think in every dp questio sir should have first expalin us recursive approach

  • @mohitahlawat4944
    @mohitahlawat4944 3 роки тому

    waohh great!! explanation sir

  • @mickyman753
    @mickyman753 2 роки тому

    Thank you sir for this beautiful explanation sir , it helps a lot to remember the method when someone explains so deeply to us

    • @muhammademmitt3243
      @muhammademmitt3243 2 роки тому

      you all probably dont give a shit but does someone know of a tool to get back into an Instagram account?
      I stupidly forgot my account password. I would love any assistance you can offer me!

  • @arvindjaiswal8013
    @arvindjaiswal8013 Рік тому

    Great explanation ❤️

  • @indranilchakraborty5949
    @indranilchakraborty5949 3 роки тому +1

    Great work Sir .I'm amazed with your style and content......though I am not a paid student but there is no difference I think between two...🙌🙌🙌🙌🙌🙌🙌🙌🙌🙌.

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      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 )

  • @kumarinidhi90
    @kumarinidhi90 2 роки тому

    Commendable job....... please make a video on Shortest Common Supersequence...

  • @uditbalyan8418
    @uditbalyan8418 3 роки тому +1

    This is best explanation. I have to come here again for understanding many other subsequences questions. 🙏

    • @Pepcoding
      @Pepcoding  3 роки тому

      Glad to hear that. Keep watching and keep supporting Pepcoding😊
      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 )

  • @archigoyal363
    @archigoyal363 2 роки тому

    Nice . Liked your video 👌

  • @shrutiemu
    @shrutiemu 3 роки тому +1

    Hello Sir ..For the same input if we have array of string instead of two string , can we deduce the formula in general

  • @angadrajsingh4311
    @angadrajsingh4311 3 роки тому +5

    sir ye series thodi shuffled hai, please isko order mei arrange kardo, flow bana rehta hai concepts and learning ka . Thanks!

  • @AnkitKumar-fj8ex
    @AnkitKumar-fj8ex 3 роки тому +1

    Awesome explanation sir

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      Glad that you liked the content and thank you for appreciating beta. I also 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 )
      Keep motivating, keep learning and keep loving Pepcoding😊

  • @rahulnaraniya1222
    @rahulnaraniya1222 2 роки тому

    thanks

  • @factswithai2
    @factswithai2 3 роки тому +1

    sir yahan tak phonchte phonchte ab maza aane laga hai dp mein, naye naye sawal bhi banne lage hain, thank u sir, and here comes a fact "east ho ya west sumeet sir is the best"

    • @Pepcoding
      @Pepcoding  3 роки тому

      keep motivating, keep learning and keep loving Pepcoding😊

  • @youngshahrukhkhan8179
    @youngshahrukhkhan8179 3 роки тому

    Very Nice Explanation......Keep making videos

    • @Pepcoding
      @Pepcoding  3 роки тому

      Thank you, I will 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 )

  • @y.so.sarthak
    @y.so.sarthak 2 роки тому +1

    sir hum kuchh bar dp left corner se right corner bharte haij kuch time me ulta
    better hota agar hum left corner se right corner bharen har baar>>>>

  • @pranjalpatel256
    @pranjalpatel256 3 роки тому +1

    keep up the good work

    • @Pepcoding
      @Pepcoding  3 роки тому

      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 )

  • @roshanthakur5745
    @roshanthakur5745 3 роки тому +1

    Great Explanation the mathematics is too good

    • @Pepcoding
      @Pepcoding  3 роки тому +3

      Longest Distinct Palindromic Sequence dekhiega

  • @tanishkumar6682
    @tanishkumar6682 Рік тому

    understood

  • @Prodcater
    @Prodcater 2 роки тому +1

    hi sir
    Can you please make a video on the Longest Common Subsequence of 3 Strings

  • @vedantingley7285
    @vedantingley7285 Рік тому

    Not able to see the proper playlist which was there previously..

  • @amberchawla7930
    @amberchawla7930 3 роки тому +3

    i was confused on how recursive sol could be derived from brute force of 2 ^ (n+m) and could not think of it from one day but now it seems total clear, thank you. Also would like to know how you developed this awesome clarity , any book recommendations or mathematics course?

    • @Pepcoding
      @Pepcoding  3 роки тому +2

      Glad I could help! keep motivating, keep learning and keep loving Pepcoding😊

    • @amberchawla7930
      @amberchawla7930 3 роки тому

      @@Pepcoding book or course recommendation ?

    • @lucky_raiser
      @lucky_raiser 2 роки тому +2

      Might he developed this skill of getting so deep into logic by practicing too much of dsa and making a mixture of all mathematical concepts (khichdi) and evolving a best solution explanation from it.

    • @adityatiwari1022
      @adityatiwari1022 2 роки тому

      @@lucky_raiser his math is really clear.

  • @NehaKumari-cx6un
    @NehaKumari-cx6un 3 роки тому

    Thanku sir

    • @Pepcoding
      @Pepcoding  3 роки тому

      Keep learning and keep growing😊
      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 )

  • @Virtualexist
    @Virtualexist 2 роки тому

    Can we also start filling this table from top left corner?

  • @rupeshdubey6461
    @rupeshdubey6461 2 роки тому

    How do we identify that this problem needs to be resolved by MCM?? Please suggest

  • @gauravbhansali2095
    @gauravbhansali2095 3 роки тому +1

    Hello...first of all thank you for your wonderful videos...it is really helpful..
    In the website,there is some problem in the compiler ... whenever I submit a solution for the first time it gives me compilation error and after that when I submit the same solution as before it gets accepted(C++)

    • @Pepcoding
      @Pepcoding  3 роки тому +4

      kra rhe hain beta theik.

  • @Anonymous-2-0-1-2
    @Anonymous-2-0-1-2 2 роки тому

    Kaha thee guru aap ❤️

  • @yashjaiswal2284
    @yashjaiswal2284 3 роки тому +1

    How many questions are left in level up as a whole sir( apart from dp)? .please tell the topics and tentatively what is that finishing date? Thanks

    • @yashjaiswal2284
      @yashjaiswal2284 3 роки тому

      Asking as per todays date (5 Nov 2020)

    • @Pepcoding
      @Pepcoding  3 роки тому +1

      total around 500 rehte hain. dec 31 the new target

  • @ritiktwopointo2691
    @ritiktwopointo2691 3 роки тому +1

    maze aa gaye..

    • @Pepcoding
      @Pepcoding  3 роки тому +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

    • @ritiktwopointo2691
      @ritiktwopointo2691 3 роки тому

      @@Pepcoding kar diya sir review :)

  • @aman6561
    @aman6561 3 роки тому +1

    Sir agr srf length hi btaaani hai longest common subsequence ki to hm do hashmap bhi to bnaa skte hai dono string ke liye or character ki frequency store krte hai.
    fr ek loop lgaa kr dekh lenge agr wo char ki frequency dono me greater than 0 hai to counter ko bdhaa lenge or end me print krdenge
    nhi work kregi kya sr ye approach?

    • @amandixit3555
      @amandixit3555 3 роки тому

      haan aise bhi kar sakte hain , par yahan hum DP padh rahe hain to uski insight ban ni important hai.

    • @riyakushwaha4347
      @riyakushwaha4347 3 роки тому +4

      This approach is not correct. For example if we take strings: adbc and aebd, your approach will give answer 3 whereas correct answer is 2(ab)

    • @mickyman753
      @mickyman753 2 роки тому +1

      bhai subsequence find krni hai , largest common permutation subset nhi , order matter krta hai

    • @KejriwalBhakt
      @KejriwalBhakt 2 роки тому

      Nope. Tumhari se permutation aa jayegi. Sequence matter karti hai warna Palindrome wali sarii question easy na ho jaati? LMAO

  • @PrinceSharma-jg2mh
    @PrinceSharma-jg2mh 3 роки тому +1

    good yar awesome

    • @Pepcoding
      @Pepcoding  3 роки тому +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

    • @PrinceSharma-jg2mh
      @PrinceSharma-jg2mh 3 роки тому +2

      @@Pepcoding did it...
      Rated 5 stars

  • @manishkumarsingh4631
    @manishkumarsingh4631 2 роки тому

    29/79 Done

    • @Pepcoding
      @Pepcoding  2 роки тому

      Keep learning and keep supporting us.
      And for better experience and curated content sign refer to nados.io

  • @jonusbrothers2067
    @jonusbrothers2067 3 роки тому +2

    Sir, I really request you to make a video for students in 7th sem, and cover every student (whether his preparation level is 20 percent or he has just started)
    TRUST ME, THIS IS THE MOST WATCHED VIDEO ON CODING BLOCKS CHANNEL, and unfortunately that video is not worth
    watching..:/
    Sir, please consider this..and try to make a video on it asap..
    Because we need you the most..this time..
    How will we strategise our preparation..
    Only you can help

  • @healthwellness4354
    @healthwellness4354 3 роки тому +1

    if string containing space then how to handle space. e.g "abdc def"

    • @Pepcoding
      @Pepcoding  3 роки тому

      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.

    • @rashim
      @rashim 3 роки тому +2

      If you treat "space" as a character, then the algorithm should remain same. No character would match with it so it would not be considered in the LCS.

  • @ayushgoel9584
    @ayushgoel9584 3 роки тому

    Sir stack, queue and LinkedList ka syllabus foundation jitna hi hai, ya abhi usko revisit karenge hum level2 mein, because almost 80% of problems which i have seen in interviews are already covered in foundation??

    • @Pepcoding
      @Pepcoding  3 роки тому

      stack-queue to majorly ho gai thi. linkedlist mei kaafi bacha hai. revisit karke honge.

  • @LegitGamer2345
    @LegitGamer2345 3 роки тому +1

    bhaari sawal

    • @Pepcoding
      @Pepcoding  3 роки тому

      kaise lga sawal? Mza aaya krne main?

    • @LegitGamer2345
      @LegitGamer2345 3 роки тому

      @@Pepcoding yes sir

    • @amandixit3555
      @amandixit3555 3 роки тому

      @@Pepcoding sir haalt kharab hogayi thi , soch ne mei. DP ne dara rakha hai buri tarike se.

  • @kumargaurav7542
    @kumargaurav7542 3 роки тому

    sir what will be the time complexicity

    • @crackthecode1372
      @crackthecode1372 3 роки тому +1

      s1.length*s2.length..jo matrix ka size h whi h complexity.

  • @helloworld6347
    @helloworld6347 2 роки тому

    this is almost LIS

  • @chitranshsaxena59
    @chitranshsaxena59 3 роки тому

    28:22 Can anyone explain how did this come

    • @AKASH-sw9bs
      @AKASH-sw9bs 3 роки тому

      watch the video from first again ... you will find it out.

  • @abhigyansharma9108
    @abhigyansharma9108 3 роки тому +1

    Sir Main aapse poore man se pdhna chahtahun par dikkat yh h ki aaap code krte ho java main aur whn mujhe dikkat hone lgti hai Main C/C++ main Smjh pata hu aur meri coding language bhi C++ hai Please Sir C++ aur Java main dono mein kr kro Please PLease

    • @Pepcoding
      @Pepcoding  3 роки тому

      c++ mei thoda time lagega.

    • @anjneykumarsingh4461
      @anjneykumarsingh4461 3 роки тому

      Bhai mn k veham h tmko, 2din d starting k lecture dekh c++, java same h. Python thora different h

    • @shang_chi4651
      @shang_chi4651 3 роки тому

      @@anjneykumarsingh4461 exactly, main khud C++ coder hoon magar input lena aur array declaration chhod ke baaki kuch alag nhi lagta mujhe

    • @Xd-dw7oe
      @Xd-dw7oe 2 роки тому

      @@shang_chi4651 yup same here

  • @aniketbhusal3489
    @aniketbhusal3489 2 роки тому +2

    though u teach well , but i wont recommend anyone to study dp from u

  • @VishalKumar-sm8bo
    @VishalKumar-sm8bo 3 роки тому

    aap smjhaye to acha hai.. lekin.. how can we think and get this logic..??

    • @Pepcoding
      @Pepcoding  3 роки тому +9

      Beta, A,B,C initally cram kri th na aur fr 20-25 baar dots jod jod k he A ya B bnana aaya th. Ab jab aise he solutions dekh k 200-300 questions kr loge to apne aap thinking capabilty develop ho jayegi aur khud se logic soch paoge aap.

    • @seemavashishth2231
      @seemavashishth2231 3 роки тому +1

      @@Pepcoding Thanx sir, btw ye msg aap krte ho ya apki team😅. Anyways thx

    • @shang_chi4651
      @shang_chi4651 3 роки тому

      @@seemavashishth2231 sir khud hi karte hain, even doosre teachers ke videos mein bhi comments ka reply sir hi karte hain

  • @shang_chi4651
    @shang_chi4651 3 роки тому

    😂😂Itna depth mein kisi teacher ko aata bhi nhi hoga LCS, poore utube oe kahin nhi hai ye explanation. Even IIT ke profs ke videos mein bhi behind the scenes waali maths nhi samjhayi gayi hai

    • @Pepcoding
      @Pepcoding  3 роки тому +2

      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.

  • @rahulkaswan6315
    @rahulkaswan6315 Рік тому

    Great Explanation, I can bet that no one could explain this, better than you , after getting your explanation i never needed to see code , saved this for future reference, thanks Sumeet sir for such a wonderful video .