Lecture 135: Longest Common Subsequence || DP on Strings

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • In this Video, we are going to learn about Dynamic Programming. This Video marks the start of India's Biggest DP Series.
    There is a lot to learn, Keep in mind “ Mnn bhot karega k chor yrr apne se nahi hoga ya maza nahi aara, Just ask 1 question “ Why I started ? “
    Discord Server Link: / discord
    Course Flow: whimsical.com/...
    Notes Link: drive.google.c...
    Slides Link: drive.google.c...
    Code Links: github.com/lov...
    Questions Links:
    - LCS: leetcode.com/p...
    Do provide you feedback in the comments, we are going to make it best collectively.
    Connect with me here:
    Instagram: / lovebabbar1
    Twitter: / lovebabbar3
    Telegram Group Link: Love Babbar CODE HELP
    telegram.me/lo...
    My Editor: www.instagram....
    Intro Sequence: We have bought all the required Licenses of the Audio, Video & Animation used.
    #DP_Series #LoveBabbar

Комментарии • 87

  • @anushkatyagi4249
    @anushkatyagi4249 Год назад +1

    Appreciation for your efforts sir👍

  • @Kinggaming-hp3qp
    @Kinggaming-hp3qp 2 года назад

    really helpful bhaiya this series is very popular in future .

  • @kunalbhika6424
    @kunalbhika6424 23 часа назад

    Understood😁😁

  • @pramantomar822
    @pramantomar822 2 года назад

    Loving the series ❤️❤️❤️❤️❤️❤️❤️❤️

  • @harpratapsinhnakoom3540
    @harpratapsinhnakoom3540 2 года назад

    Feeling proud to reach near the end

  • @FaizanKhan-gfaizank
    @FaizanKhan-gfaizank Год назад

    Couldn't have been better!!

  • @pragyaverma2105
    @pragyaverma2105 Год назад

    Thank you ji ❤

  • @bestlyrical3843
    @bestlyrical3843 8 месяцев назад

    Amazing content

  • @manishdv1331
    @manishdv1331 2 года назад +6

    Sir apka ye series maine kuch hi din pehle start kiya hai .
    You are providing an amazing content which makes it easy for anyone to understand computer programming.
    You are doing an amazing job!! Thank you sir!! @LoveBabbar

  • @anshikasingh4158
    @anshikasingh4158 Год назад

    mazza aaya

  • @NiteshYadav-dg8lh
    @NiteshYadav-dg8lh 2 года назад +1

    🔥🔥

  • @itspurelypassionate
    @itspurelypassionate Год назад

    Thanks!

  • @VinodKumar-hm6do
    @VinodKumar-hm6do Год назад

    Best sir happie to be student of you

  • @GauravHaritas
    @GauravHaritas Год назад

    Bhaiya #QnA Why didn't you go to foreign country for job purpose or to stay there itself ?

  • @BombSquadHindiTipsTricks
    @BombSquadHindiTipsTricks 6 месяцев назад

    can this ques be solved using 4 variables only?

  • @vedantraut256
    @vedantraut256 Год назад +21

    // COMPLETE CODE WITH COMMENTS
    class Solution {
    public:
    int solve(string& a, string& b, int i, int j){
    // Base Case
    if(i == a.length())
    return 0;
    if(j == b.length())
    return 0;
    int ans = 0;
    if(a[i] == b[j])
    ans = 1 + solve(a, b, i+1, j+1);
    else
    {
    ans = max(solve(a, b, i+1, j), solve(a, b, i, j+1));
    }
    return ans;
    }
    int solveMem(string& a, string& b, int i, int j, vector &dp){
    // Base Case
    if(i == a.length())
    return 0;
    if(j == b.length())
    return 0;
    if(dp[i][j] != -1)
    return dp[i][j];
    int ans = 0;
    if(a[i] == b[j])
    ans = 1 + solveMem(a, b, i+1, j+1, dp);
    else
    {
    ans = max(solveMem(a, b, i+1, j, dp), solveMem(a, b, i, j+1, dp));
    }
    return dp[i][j] = ans;
    }
    int solveTab(string& a, string& b){
    int n1 = a.length();
    int n2 = b.length();
    vector dp(n1+1, vector (n2+1, 0));
    for(int i = n1-1; i>=0; i--){
    for(int j = n2-1; j>=0; j--){
    int ans = 0;
    if(a[i] == b[j])
    ans = 1 + dp[i+1][j+1];
    else
    {
    ans = max(dp[i+1][j], dp[i][j+1]);
    }
    dp[i][j] = ans;
    }
    }

    return dp[0][0];
    }
    int solveSpaceOP(string& a, string& b){
    int n1 = a.length();
    int n2 = b.length();
    vector dp(n1+1, vector (n2+1, 0));
    vector currRow(n2+1, 0);
    vector nextRow(n2+1, 0);
    for(int i = n1-1; i>=0; i--){
    for(int j = n2-1; j>=0; j--){
    int ans = 0;
    if(a[i] == b[j])
    ans = 1 + nextRow[j+1];
    else
    {
    ans = max(nextRow[j], currRow[j+1]);
    }
    currRow[j] = ans;
    }
    nextRow = currRow;
    }

    return nextRow[0];
    }
    int longestCommonSubsequence(string text1, string text2) {
    // RECURSION
    // return solve(text1, text2, 0, 0);
    // RECURSION + MEMOIZATION
    /*
    int n1 = text1.length();
    int n2 = text2.length();

    vector dp(n1+1, vector (n2+1, -1));
    return solveMem(text1, text2, 0, 0, dp);
    */
    // TABULATION
    // return solveTab(text1, text2);
    // SPACE OPTIMIZATION
    return solveSpaceOP(text1, text2);
    }
    };

    • @ultimategyani6412
      @ultimategyani6412 Год назад

      Bhai for loop ulte se hi kyu chalaye tabular wle mein...sidhe kyu ni chla skte???🥲

    • @codingindisguise
      @codingindisguise Год назад

      @@ultimategyani6412 Bhai loop seedha Top-Down mei lagate hain i.e. Memoization mei. Tabulation ka concept hi Bottom-Up approach hai toh ulta chalta hai...

    • @sahilsingh5695
      @sahilsingh5695 Год назад

      we need more people like you

    • @Anandkumar09876
      @Anandkumar09876 6 месяцев назад

      TLE aa raha hai

  • @jaydhanwalkar9665
    @jaydhanwalkar9665 9 месяцев назад

    UNDERSTOOD+++++++;

  • @atifhu
    @atifhu Год назад +3

    top down approach is no more accepted in my solution.

    • @karthikmadan
      @karthikmadan 4 месяца назад

      pass string by reference

    • @akmarkan2490
      @akmarkan2490 2 месяца назад +1

      Why does it matter bro???​@@karthikmadan

  • @deepakumar01
    @deepakumar01 2 месяца назад

    Sir aapne top down me jo space Kam karne k liye do row liya hai usme aapne bola unki size min(lengths of strings) but ye galat hai aapko max Lena padega

  • @nitishkumar-ol1fx
    @nitishkumar-ol1fx Год назад

    ❤❤

  • @ajaychandel9976
    @ajaychandel9976 Год назад +2

    maza aa gaya🔥🔥🔥🔥🔥🔥

  • @vishalgarna4580
    @vishalgarna4580 Год назад +1

    All clear bhaiya 😊😊😊

  • @praveennemagoudar3442
    @praveennemagoudar3442 7 месяцев назад +2

    U r genius Bhaiya. Hats off. GOD of DSA.

  • @arvindmali5179
    @arvindmali5179 Год назад +1

    Amazing video as always....Thankkk youuuu bhaiya😍

  • @madhavmahajan6109
    @madhavmahajan6109 Год назад

    ❤❤❤❤❤❤❤❤

  • @keshavgupta333
    @keshavgupta333 2 года назад

    Bhaiya apki videos great hai

  • @harshdubey4030
    @harshdubey4030 6 месяцев назад

    understood ++

  • @RandomGuy-xq1hk
    @RandomGuy-xq1hk 6 месяцев назад

    nice video ❤❤❤

  • @ravindrashinde9305
    @ravindrashinde9305 Год назад +2

    One and only one best series on DP👌

  • @mitalisaraswat57
    @mitalisaraswat57 Год назад

  • @dakshkumar7765
    @dakshkumar7765 3 месяца назад

    😀

  • @MittuRohith
    @MittuRohith Год назад

    🤗

  • @iteself_me
    @iteself_me Год назад

    58 ✅completed 👍Liked 04:12

  • @vimalrai2092
    @vimalrai2092 Год назад

    i noticed the mistake of +1 in vector intialization in the solveTabulation function earlier😁😁😁

  • @Sambyal-n2y
    @Sambyal-n2y 7 месяцев назад

    Appreciate your work. Thank you so much.

  • @Motivational_talks
    @Motivational_talks 11 месяцев назад

    yes understand ++

  • @MrKB_SSJ2
    @MrKB_SSJ2 Год назад

    SOOO GENIUS ANSWER YOOOOOOOO

  • @codingindisguise
    @codingindisguise Год назад

    L views, W content❤

  • @harshik7460
    @harshik7460 Год назад

    how to print that lcs ??

  • @jatinranjan7954
    @jatinranjan7954 Год назад

    Arigato gozaimasu🙇‍♂

  • @nothinginsideme
    @nothinginsideme Год назад

    Very nice explanation sir, thank you so much

  • @mycollegeLife.
    @mycollegeLife. Год назад

    Nice nhi ....... phaaduuuuuuuu

  • @studygainer5482
    @studygainer5482 Год назад

    completed

  • @apurav363
    @apurav363 2 месяца назад

    Thankyou bhaiya ❤

  • @Deepak-um1zq
    @Deepak-um1zq Год назад

    Thank you bhaiya for such amazing content.☺

  • @kumarshubham4327
    @kumarshubham4327 Год назад

    consistency++

  • @arnavumarkar8259
    @arnavumarkar8259 Год назад

    nice

  • @Aakash-qr6ky
    @Aakash-qr6ky Год назад

    thanks love bober

  • @parthagarwal1086
    @parthagarwal1086 Год назад

    Very nice video

  • @KratosProton
    @KratosProton Год назад

    t

  • @KratosProton
    @KratosProton Год назад

    a

  • @abhaythakur2597
    @abhaythakur2597 Год назад

    very well explained

  • @aftabtechnical7965
    @aftabtechnical7965 8 месяцев назад

    👍

  • @rohitkumarmeena2576
    @rohitkumarmeena2576 Год назад

    maza aa gaya🔥🔥🔥🔥🔥🔥

  • @rahulsinghaswal07
    @rahulsinghaswal07 6 месяцев назад

    bhut asani se samjh aa gya bhaiya

  • @huzaifaqureshi3329
    @huzaifaqureshi3329 Год назад

    Thank you sir 🙌

  • @Vital_Truth
    @Vital_Truth 2 года назад

    I really love to learn by you 😍❤

  • @priyanshukhandelwal6631
    @priyanshukhandelwal6631 9 месяцев назад

    maza aa rha h bhaiya

  • @magangagan6535
    @magangagan6535 Год назад

    thanks bhaiya

  • @govindsuryavanshi6653
    @govindsuryavanshi6653 Год назад

    🔥

  • @shivakatara782
    @shivakatara782 2 года назад

    nice

  • @ayushgupta1881
    @ayushgupta1881 Год назад

    Thanks a lot bhaiya

  • @iitianashishmadhukar9861
    @iitianashishmadhukar9861 Год назад

    smj mai aa gya ❤❤❤❤❤+++++

  • @himanshugautam3668
    @himanshugautam3668 Год назад

    🙌🙌🔥

  • @vkgg6124
    @vkgg6124 Год назад

    Thanks bhaiya ❤

  • @piyushgaur6975
    @piyushgaur6975 2 года назад

    bhadiya

  • @nishankdeep3084
    @nishankdeep3084 2 года назад

    thank you bhaiya
    samagh aa gaya

  • @harshvardhan9438
    @harshvardhan9438 Год назад

    👏👏

  • @codewith_ayushluthra5248
    @codewith_ayushluthra5248 Год назад

    maza aa gaya

  • @tejasshaha6629
    @tejasshaha6629 2 года назад

    Amazing content bhaiya ❤

  • @RajSingh-rn1yw
    @RajSingh-rn1yw Год назад

    🔥🔥🔥

  • @sukhjitsingh959
    @sukhjitsingh959 2 года назад +1

    Thanks Babbar Sir Fire 🔥 back to finish Dp series

  • @manishdv1331
    @manishdv1331 2 года назад

    Sir apka guidance mujhe sahi mai zaroorat hai iss stream se related
    Mai iss saal jee mains mein qualify hua hu aur apka reply bahut help karega sir
    So where can I send a message to you sir??
    I tried on Instagram, Gmail and LinkedIn.
    (Ignore my grammar)

  • @KratosProton
    @KratosProton Год назад

    e

  • @sujalkumar4948
    @sujalkumar4948 2 года назад

    sir ish series ke play list link ??

  • @flickboi2322
    @flickboi2322 2 года назад

    Bhaiya ajhi khatam kardo DP Series maja a jaiga 😅

  • @harikrushnasuhagiya3925
    @harikrushnasuhagiya3925 2 года назад

    Dil Jit Liya Bhaiyaa

  • @your_dad_18
    @your_dad_18 2 года назад +1

    Reach++;