Find the longest Palindrome in a string | Love Babbar DSA Sheet | Amazon🔥

Поділитися
Вставка
  • Опубліковано 5 лют 2025
  • #competitiveprogramming #dsasheet #interviewpreparation
    In this video I have solved the problem of the sheet i.e. Write a program to find the longest Palindrome in a string.[ Longest palindromic Substring]
    Complete Explaination with code.
    String question Playlist = • Love Babbar DSA 450 Qu...
    Array question Playlist = • Love Babbar DSA 450 Qu...
    Love Babbar DSA Sheet : drive.google.c...
    Hope you like it. Comment if you have any doubt
    LIKE | SHARE | SUBSCRIBE

КОМЕНТАРІ • 92

  • @abhishekprasad9276
    @abhishekprasad9276 4 роки тому +82

    If u guys complete these 450 questions definitely your channel will become very famous 🔥

  • @sharuk3545
    @sharuk3545 3 роки тому +21

    bhai starting me btaya h asi jgh jha bb equal mlte h but usse phle to aa equal milege uska kya (1:16-1:20) you directly jumped it bb without saying aa. Your logic is good but explain properly

  • @supradipdey1165
    @supradipdey1165 3 роки тому +16

    At 1:24 min, "aa" is also equal at first so then why does the pointer stop only "bb". Explain Please.

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

    Thank You Bhaiya, Abse yahi channel follow hoga till the placement.

  • @rishurana9655
    @rishurana9655 3 роки тому +11

    for those who want to do this question in O(N) complexity can learn about Manacher’s Algorithm

  • @sumitjindal1115
    @sumitjindal1115 4 роки тому +10

    pls explain the intuition behind the algorithm.

  • @mohammedwaseem8599
    @mohammedwaseem8599 3 роки тому +6

    Bro Dry Run The Case Explain Code With Taking Example.

  • @alt-f4gaming222
    @alt-f4gaming222 2 роки тому

    wow outstanding approach

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

    great explaination !!

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

    thanks bhai for this solution , i saw other youtube chnanels and they are directly starting from dp tabulation , your solution was easiest to understand

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

    Awesome!

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

    very nice explanation bro....thanks

  • @tridevthakur5397
    @tridevthakur5397 4 роки тому +2

    💢💢💢Excellent work💢💢💢

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

    Keep it up brother 👍👍

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

    Keep it up 👍👍👍very nice explanation

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

    nice explaination

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

    hey , how do we check if the current substring length is greater than the previous one ??
    PS:- what is the use of end=1 and then comparing h-l+1>end??

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

      To update the starting index and length of palindromic substring if its length is greater than previous one(stored in end variable)

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

      chutiye dry run kr mc

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

    Thank you Bhai ! for simplest solution in of this problem on youtube !

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

    If we are giving input as "aba " Then output is coming out to be an "a"..... But it should comeout aba as it is longest substring?????.... Plzz clear my doubt

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

    Keep going brother😊

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

    Crystal clear explanation,🙇🙇🙇

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

    bhai isme hamne to comments likh die odd and even string , but code mein check ni lagana chahiye ki agar length odd hui to alg while loop and even hui to alag while loop

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

      bhai tum galat samjh rhe . agar samjhna hai tho reply kro samjhata hu

  • @BLAZE-wn7di
    @BLAZE-wn7di 3 роки тому +1

    Dhnyawaad

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

    Thanks bro

  • @PranavPrajapati-hd2eu
    @PranavPrajapati-hd2eu 2 роки тому

    We here to check if length of string is even or odd?

  • @MohitKumar-yr4rl
    @MohitKumar-yr4rl 3 роки тому +4

    string longestPalin (string S) {
    // code here
    int start=0;
    int end=0;
    int low,high;
    int n=S.length();
    for(int i=0;i=0 and high

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

      thank you bro this is helpful

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

    //java code
    class Solution{
    static String longestPalin(String S){
    // code here
    int start=0;
    int end=0;
    int low,high;
    int n=S.length();
    for(int i=0;i=0 && high

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

      Bro please clear my doubt do we need to write code which satisfies only the given input below problem or for any input please reply

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

      obviously any input given bro, condition is the input type must be same @@intrestingscienceworld5848

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

    intuition kaise aai iss approach ki>

  • @anshulvairagade1604
    @anshulvairagade1604 4 роки тому +2

    How the compiler knowing which while loop to use, you didn't check if length of the string is even use this or else
    Please help me ? Where I'm wrong ?

    • @CodeLibrary
      @CodeLibrary  4 роки тому +7

      I got it where you are going wrong... Basically for each i we are checking a even as well as odd substrings and which ever will give the better result we will print that...see their in odd substrings section we are updating l and h

    • @anshulvairagade1604
      @anshulvairagade1604 4 роки тому +2

      @@CodeLibrary thank you so much my clearing my doubt I've been scratching my head since yesterday
      You are the best 🔥

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

    the other guy on this channel explain well, nd you need to improve bro in explaination.

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

    at 5:37 , you didnt initialize the end, why did you miss it?

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

    how can you write your own main method in GFG i dont think it is possible

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

    So for each character in the given string we have to check both the conditions ?? .If so can you explain why we have to check both the conditions ?

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

      because we don't whether our substring will be odd or even

  • @vishaldange2163
    @vishaldange2163 3 роки тому +6

    How did you remove the default code in gfg practice ?

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

      he is having premium subscription of GFG , so he can change his IDE according to him :)

  • @kSERITIKGupta
    @kSERITIKGupta 4 роки тому +2

    I am facing problem,I used your approach to solve the problem, I tried to compile and run it on GFG ,it showed the correct output but when I submitted it,it shows that you got wrong answer,even I tried this on different IDE and all of them showed correct answers,plz reply

    • @vasugoyal7864
      @vasugoyal7864 4 роки тому +1

      Put endl after calling palindrome(string s) in the main function.

  • @SunilGupta-qx6xe
    @SunilGupta-qx6xe 2 роки тому

    @anyone, why we are sending start+end-1 instead of end. Please explain?

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

      We might be getting the value of end smaller than start....that's why he has considered start+end-1

  • @sharad3877
    @sharad3877 Рік тому +2

    can someone please explain me, why we passed (start+end-1), as end parameter in printString function and not (end-start+1)?

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

      Lets take ex of caabbabd here the start is 2 so they passed it so that the printing starts from here and till start+end-1 which would be 2+5-1=6(in S, 6th is the index which contains the char just after the end char of the palindrome string) so if it prints till < 6 it will be basically the palindrome string. Also I think they should have just written

  • @HIMANSHUVERMA-wu1hc
    @HIMANSHUVERMA-wu1hc 3 роки тому +2

    "wtwkee" this code will produce "ee" but the answer is "wtw" your logic failed brother anyway it added a new thinking approach to us.

  • @DikshaKumari-cy9yl
    @DikshaKumari-cy9yl 3 роки тому +1

    code not working now

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

    Amazing explanation 😍♥️

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

    "wtwosileez" wrong for this test case...ur code will return "ee"..but actual output is "wtw" .

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

    Not working on leetcode.

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

    if string will be "rajjjkmnmkj" then its output should be "jkmnmkj" but this code will return jj

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

    hey can u explain me if my element at 0th and 1th position are same and if we do low__then that low which is allready points to 0 decreases to -1then how this soln is correct?

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

    bhai ye batao tumse saare ques kese ho jaa rahe hai ? kahi atakte nhi ho kya aur kitna tym dete ho pr ques ke optimal soln tk aane mein?

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

      bhai ye sre ans gfg pe mil jate he brute optimal or best,ye bs explain kr rhe he.

  • @somith16
    @somith16 4 роки тому +5

    sir can u explain how this is 0(n^2) complexity

    • @Shivamkumar-xu6hu
      @Shivamkumar-xu6hu 3 роки тому +1

      Because
      For first loop it's O(n) and two loops are inside it.
      So, O(n*(N+N)) = O(n*n)

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

    Also explain java solution code

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

    What I am doing wrong, anybody can help
    string longestPalin (string S) {
    // code here
    string z="";
    int n=S.length();
    int l=0,L=0;
    int r=0,R=0;
    for(int i=1;i=0&&rR){
    L=l;
    R=r-l+1;
    }
    l--;
    r++;
    }
    l=i-1;
    r=i+1;
    while(S[l]==S[r]&&l>=0&&rR){
    L=l;
    R=r-l+1;
    }
    l--;
    r++;
    }
    }
    for(int i=L;i

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

    If I am giving abaa it is giving aa as an output..... Why is it so???.... It should give aba

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

    what about "abcd" it will not print "a" in this case

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

    try for this string "eeef" it may fail

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

    It'll fail for string "abb"

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

    Bhai tum chhor do yaar padhana, aadhi chize to tum explain bhi nahi krte ho ki konsa variable kahan se initialize ho raha or kya initial value hai...

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

    someone please explain me what is h-l+1>end clearly .....?

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

      we are just checking if the current length of palindrome is greater than the previous length if so we will update...Here "h" and "l" are respectively pointing to the start and end of the current palindrome substring and "end" contains the length of the previously found out palindrome substring.

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

      @@siri3359 why will the length of previously found out palindrome substring be equal to "end" and not "end-start"?

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

      @@niharsrivastava end variable means length of max string. start variable means starting position of max string. h-l+1 is length of the current string. In the end, he is passing starting position and ending position to print the string using his created function

  • @sumedhkamble8378
    @sumedhkamble8378 4 роки тому

    Why Lcs is not useful here ??

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

      coz lcs works for subsequence and it may be palindrome or may be not

  • @prashantMishra-it2im
    @prashantMishra-it2im 2 роки тому

    could have been a better explanation

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

    Sir
    Kindly explain in English
    Many users may not understand Hindi

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

    i didnt understand the line number 29 and 30, very bad explaination, just writing the code

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

      dont worry, will update the older videos

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

    Not so hard

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

    L explanation

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

    Ghatiya explanation

  • @KuldeepSingh-yt4xg
    @KuldeepSingh-yt4xg Рік тому

    WRONG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!