DP 29. Minimum Insertions to Make String Palindrome

Поділитися
Вставка
  • Опубліковано 22 чер 2024
  • Lecture Notes/C++/Java Codes: takeuforward.org/dynamic-prog...
    Problem Link: bit.ly/3H2ZtGP
    Pre-req for this Series: • Re 1. Introduction to ...
    a
    Make sure to join our telegram group for discussions: linktr.ee/takeUforward
    Full Playlist: • Striver's Dynamic Prog...
    In this video, we solve the minimum insertions to make a string palindrome, before watching this please make sure to watch the DP 28 video.
    If you have not yet checked our SDE sheet, you should definitely do it: takeuforward.org/interviews/s...
    You can also get in touch with me at my social handles: linktr.ee/takeUforward

КОМЕНТАРІ • 323

  • @shubhamrawat2353
    @shubhamrawat2353 2 роки тому +175

    The ans for minimum no. of deletions to make a string palindrome will also be same because if we just remove the characters which are not a part of the lps(longest palindromic subsequence) we'll get the ans...which is same as n-len(lps)

    • @udatyadeb101
      @udatyadeb101 11 місяців тому +4

      this is making more sense to me.......

    • @RajeevCanDev
      @RajeevCanDev 11 місяців тому +1

      Great 👍🏻

  • @rishavsaha5254
    @rishavsaha5254 2 роки тому +22

    Previously, I heard that DP is some sort of topic, people use to leave, but now after watching each and every video of Striver, I must say you just made it the easiest.
    Write the recursion -> change it to memoization -> change it to tabulation.
    And the relation you develop between questions, is just incredible. Keep growing.

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

      dp is a marathon not that tuff , if teacher is good its a cakewalk

  • @sahilgagan2242
    @sahilgagan2242 Рік тому +27

    52% done .... striver bro u build my logic ... now i can solve any pattern of dp taught till now .... and also i solved all the problems by myself when u just write sudo code for new topic .... thanks striver bro ...

  • @elakkiahmasi8887
    @elakkiahmasi8887 Рік тому +14

    Hi Striver, I have been following your videos for the past three months and dp series since last week. I really had to admit how graceful you are in teaching, I thank you a lot for your contribution and today I solved myself this question without looking into the solution and now I am going to watch it to make a note of your points if I had missed anything. And since I started your dp series, I have handwritten all the things that you had said and I am also finding it very useful for revision. Thanks again

    • @BeatXRitik
      @BeatXRitik Місяць тому

      Can you send me those notes

  • @ranasauravsingh
    @ranasauravsingh 2 роки тому +9

    TOTALLY UNDERSTOOD... !!!
    That just blew up my mind...
    Thank you striver for the video... :)

  • @MayankLC93
    @MayankLC93 Рік тому +4

    i did this by own !!! i am loving it that i came up to the solution by own . Thank You Striver !!

  • @immortal6978
    @immortal6978 7 місяців тому

    I initially tried with my own and with way you teach I was able to solve it by my own.
    Thanks understood one more lecture.

  • @ishangujarathi10
    @ishangujarathi10 Рік тому +13

    man GOD level stuff Striverrr, it was a leetcode HARD problem, but the logic you told makes it look a EASY level problem!!!! Thanks a lotttt!!

  • @aniruddhakotal1534
    @aniruddhakotal1534 8 місяців тому

    hats off to you !!! Proved that , every topic is easy if you got the right teachings..

  • @zerr0n7eet
    @zerr0n7eet Рік тому +7

    Solved this without even watching. Thanks bro

  • @stith_pragya
    @stith_pragya 5 місяців тому +1

    UNDERSTOOD.......Thank You So Much for this wonderful video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻

  • @aadithyaseshadri9597
    @aadithyaseshadri9597 Рік тому +16

    Understood! A small clarification - at 8:35 , when you kept the palindromic section in tact, shouldn't you have taken "cod" instead of "codi" while switching? That along with "sajn" would give the minimum insertions to be 3+4 = 7 right?

  • @vikashkumar7762
    @vikashkumar7762 2 роки тому +7

    Waoooh... Previous lecture concept move this LC hard level question to medium level

  • @user-or7xr2mt3o
    @user-or7xr2mt3o Рік тому

    Understood....the way u explain DP, seems like DP is piece of cake!!

  • @pulkitchausali1354
    @pulkitchausali1354 Рік тому +4

    "Logic formed just by seeing example test cases" came to video to insure that i am thinking right THANKU Striver

  • @johncenakiwi
    @johncenakiwi 2 роки тому +9

    Understood!! LCS pattern can help us solve so many problems!! Thanks Striver

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

      LCS?? What's LCS, He was saying LPS or LCS!??

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

      @@Mojemoye LONGEST COMMON SUBSEQUENCE

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

      @@Mojemoye lps will also be done by lcs

    • @pqrstwxyz1175
      @pqrstwxyz1175 6 місяців тому

      One question; Is LCS pattern enough for solving any dp on string problem?

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

    understood, thank you so much.

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

    Thanks a lot bro..... I really appreciate you!

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

    Understood! I really really appreciate for your explanation!!

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

    got the logic just after your first exmaple. Thank you Raj bhaiya

  • @sooyashjaju4208
    @sooyashjaju4208 Рік тому +20

    Minimum Insertions To make palindrome = (length of string - * length of longest palindromic Subsequence *) [DP 29],
    and Length of Longest palindromic Subsequence = (* longest common Subsequence * between String and its Reverse ) [DP 28]
    And longest common Subsequence, we know it already !! [DP 25]
    What a link !
    matlab questions naye ate jaa rhe h bss , baki jitna sikha h unhi me se uska solution mil rha h, thoda observation acha ho toh 😀
    man gye bhai ! ❤
    Itni ache se design ki h playlist ki aap gadhe se Gadhe ko bhi sikha skhtein ho, bs uski sikhne ki ichha ho

  • @Hrushi_2000
    @Hrushi_2000 9 місяців тому

    Understood. Thankyou sir

  • @worldofniyathi
    @worldofniyathi 16 днів тому +1

    hats off to you

  • @MP-ny3ep
    @MP-ny3ep Рік тому

    Terrific explanation. Thank you so much !!!

  • @harshitjaiswal9439
    @harshitjaiswal9439 11 місяців тому +1

    8:06 promotion at its best XD. Understood as always Striver!

  • @user-qi3eh5jq4v
    @user-qi3eh5jq4v 2 роки тому +4

    Bhaiyaa we are so so grateful for your content and effort🙏❤

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

    Understood, sir. Thank you very much.

  • @shivisingh9975
    @shivisingh9975 2 місяці тому

    Understood sir!

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

    man hatsoff to you striver
    Intuition just clicked in by just seeing the topic of video,
    and converted it into code under just 5 mins and easily did a leetcode hard problem
    so thanks again striver for such an amazing content

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

    Understood. Amazing explanation!

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

    understood sir, u are amazing , love the way u teach.

  • @gunduboinadileep9523
    @gunduboinadileep9523 6 місяців тому

    understood!!.

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

    Bhaiya i understood the concepts upto dp on subsequences very well also did the questions without watching or seeing the solutions but this dp on string topic , i understand the solution properly but can't do problem by my own . Anyway ... understoo the solution. Thanks ❤

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

    understood!

  • @ramakrishnakcr4417
    @ramakrishnakcr4417 3 місяці тому

    thank you

  • @prabhakaran5542
    @prabhakaran5542 2 місяці тому +1

    Understood ❤

  • @UECAshutoshKumar
    @UECAshutoshKumar День тому +1

    Thank You
    Understood!!!!!

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

    Understood!!!Thank you

  • @alifarah9
    @alifarah9 2 роки тому +5

    please do word break & word break ii. thanks

  • @tasneemayham974
    @tasneemayham974 8 місяців тому

    BESTTT TEACHERRR EVERRR!!!!!!!!!!!!!!!!1

  • @saurabhrthakur
    @saurabhrthakur 2 місяці тому

    Understood!

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

    your videos are awesome. Please suggest system design related training

  • @priyanshu6173
    @priyanshu6173 3 місяці тому +1

    This is a Hard category question on leetcode but u made it a piece of cake lmao ❤

  • @radharamamohanakunnattur3035

    Awesome!! Understood!!

  • @mohitagarwal3639
    @mohitagarwal3639 2 роки тому +6

    i did this question in another way and that is accepted with 100 % score.
    Kindly take a look....
    Memoized solution -
    int f(int l, int r, string &str, vector &dp)
    {
    if (l >= r)
    return 0;
    if (dp[l][r] != -1)
    return dp[l][r];
    if (str[l] == str[r])
    return dp[l][r] = f(l + 1, r - 1, str, dp);
    else
    return dp[l][r] = 1 + min(f(l + 1, r, str, dp), f(l, r - 1, str, dp));
    }
    int minInsertion(string &str)
    {
    int n = str.size();
    int a = 0, b = str.size() - 1;
    vector dp(n, vector(n, -1));
    return f(a, b, str, dp);
    }
    Tabulation -
    int minInsertion(string &str)
    {
    int n = str.size();
    int a = 0, b = str.size() - 1;
    vector dp(n, vector(n, 0));
    for (int l = n - 2; l >= 0; l--)
    {
    for (int r = l + 1; r < n; r++)
    {
    if (str[l] == str[r])
    dp[l][r] = dp[l + 1][r - 1];
    else
    dp[l][r] = 1 + min(dp[l + 1][r], dp[l][r - 1]);
    }
    }
    return dp[a][b];
    }
    Thanks Striver for this complete DP playlist.

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

      what is your dp state?? means what dp[i][j] represent

  • @pragyanandsingh6673
    @pragyanandsingh6673 4 місяці тому

    Understood !!

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

    got the idea @ 5:19 we can do length()-LPS thank you striver for such amazing videos

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

    Understood, thanks a ton

  • @CEBMANURBHAVARYA
    @CEBMANURBHAVARYA 11 місяців тому

    demn i just tried the question first without starting video, just changed return dp[n][n] to n-dp[n][n], and lol it worked, and on leetcode it was a hard ques, I didn't believe, so I saw ur video, and yea it was indeed easy, after doing the LPS ques.

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

    Understood Sir thank you very much

  • @rahulsidhu5945
    @rahulsidhu5945 11 місяців тому

    Just want to say... You are awesome striver😇😇

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

    Understood Thanks Striver ❤

  • @aruna5869
    @aruna5869 3 місяці тому

    understood :)❤

  • @keshavprasad1017
    @keshavprasad1017 8 місяців тому

    Best❤

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

    Striver thankyou
    first time in dp i did this question without watched your video
    thanks

  • @niteshmodi5468
    @niteshmodi5468 9 місяців тому

    ye badhiya tha guru...ji...

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

    We are glad to have u brother

  • @atindraask8074
    @atindraask8074 Місяць тому +1

    Understood

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

    Understood !!!!!

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

    US, mindblowing explanation

  • @verma_jay
    @verma_jay 8 місяців тому

    understood

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

    Understood. You made dp easy.

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

    All Character (at opposite position) which are not part of longest palindromic subsequence

  • @yikes3807
    @yikes3807 11 місяців тому

    bro made leetcode hard look like a lollypop thanks striver loving this dp series

  • @himanshuagrawal8012
    @himanshuagrawal8012 2 роки тому +10

    LCS is just Like Striver....It helps us to solve most of the problems ........Sorry for the PJ #UNDERSTOOD

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

    Understood🌻

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

    understood bhai , thanks !

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

    understooodd!!!!

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

    Understood Bhai. Have a request. Is it possible to explain the logic and code for the "look and say" or "count and say" problem bro? thanks in advance. it would really help if you could.

  • @fragz8376
    @fragz8376 11 місяців тому +1

    understood 29/57 completed!

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

    understood 👍

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

    understood bhaiya❤❤

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

    Understood🔥🔥

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

    how can we print the modified string which will be palindrome string after minimum no operations

  • @arihantjammar8888
    @arihantjammar8888 8 місяців тому

    😅 Understood 😊

  • @googleit2490
    @googleit2490 7 місяців тому

    Done and dusted in DP revision
    Nov'14, 2023 05:54 pm

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

    How to print the converted string? I mean after insertions, The final palindromic string

  • @VikashYadav-px8ei
    @VikashYadav-px8ei Рік тому +1

    Understood 🎉

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

    Understood !!!🥰🥰🥰

  • @Ajay-ei2jo
    @Ajay-ei2jo Рік тому

    Understood 👍

  • @Hello-ro6hr
    @Hello-ro6hr Рік тому

    UNDERSTOOD ...

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

    Understood.

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

    understood!!

  • @RitikKumar-bk6pj
    @RitikKumar-bk6pj 2 роки тому +1

    Bhaiya muje string ke question mai bilkul confident nhi hai mai wo kese strong kru aapne?

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

    Understood❤

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

    Understood 🥰

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

    Thanks

  • @shubhansu-kr
    @shubhansu-kr Рік тому

    Enlightenment

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

    Great!!

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

    this question was rated hard in leetcode after seeing ur explanation i was like why is it rated hard?

  • @ayanangshudasmajumder112
    @ayanangshudasmajumder112 9 місяців тому

    Understood!!!

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

    Understood kaka!

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

    understood❤❤❤

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

    *As we are not passing the string by reference '&' then also the code is running fine, can anyone explain this*

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

    Apparently this playlist is sponsored by Coding Ninjas, Best marketing move.

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

    US, half playlist completed😄

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

    understoood bhaiya

  • @Nitro-kx7ok
    @Nitro-kx7ok Рік тому

    Understood sir🙇‍♂🙏❤

  • @ShubhamKumar-fn5be
    @ShubhamKumar-fn5be 10 місяців тому

    understood 😄😄

  • @i.mandeepgoyal
    @i.mandeepgoyal Рік тому

    Great