Manacher's Algorithm | Longest Palindromic Substring

Sdílet
Vložit
  • čas přidán 26. 03. 2020
  • In this video I will be discussing Manacher's algorithm which is used to find the longest palindromic substring in linear time. Its a fairly complex algorithm and understanding its time complexity is the hardest part. So, in this video I will help you understand it to the fullest.
    Practice problems :
    Easy - www.codechef.com/problems/PALIN3
    Hard - codeforces.com/contest/1080/p...

Komentáře • 51

  • @sanskarmani9094
    @sanskarmani9094 Před 4 lety +5

    Too good. Thanks for explaining it in so simple terms and also for covering every case.

  • @suhanibajpai4025
    @suhanibajpai4025 Před rokem +2

    this is the best video among all the videos on youtube explaining manacher's algorithm

  • @dhruvsingh5190
    @dhruvsingh5190 Před 6 měsíci +2

    best explanation found till now for this algorithm.🔥🔥

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

    Well Explained! Among all the videos about Manacher's Algorithm, your explanation is best. Thank you for making this video.

  • @Lime-rr6te
    @Lime-rr6te Před 3 lety +5

    this was the best manachers algo explanation i found, better that tushar roy, tech dose, nick white
    and so many others

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

    very clear and comprehensive video. The best explanation for Manacher's Algorithm!

  • @shubhamagrawal7557
    @shubhamagrawal7557 Před rokem +1

    Great Video. Thanks for the simple and intuitive explanation!

  • @shashwattripathi759
    @shashwattripathi759 Před 4 lety +1

    All of your videos are just amazing !
    Please make more videos...!
    Thanks a lot !

  • @vivekpandya2163
    @vivekpandya2163 Před 3 měsíci

    Just watching first 4 mins and I found its very fluent and easy to understand. 🙏

  • @user-vn4jw3ch8w
    @user-vn4jw3ch8w Před rokem

    one of the youtuber that can explain manacher pretty well , respect

  • @xiaoxiaodeng3957
    @xiaoxiaodeng3957 Před 4 lety

    Thank you, your video helps a lot.

  • @yaswanthchunduru5298
    @yaswanthchunduru5298 Před 3 lety

    Bro your videos are literally awesome.

  • @sylviazhang6786
    @sylviazhang6786 Před 2 lety

    Thank you. It is very well explained.

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

    Best explaination on the internet

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

    Nice explanation!

  • @motivation9718
    @motivation9718 Před 4 lety +1

    Great explanation brother.....

  • @zaksification
    @zaksification Před 3 lety

    Really great explainaion

  • @ArpitMarkana
    @ArpitMarkana Před měsícem

    good explaination

  • @pranavbansal9934
    @pranavbansal9934 Před 4 lety

    best explanatiion!!

  • @sanskarmani9094
    @sanskarmani9094 Před 4 lety +1

    Can you also consider making a video on Ford Fulkerson max flow algorithm??

  • @sarathchandrakalahasti1484

    Good explanation

  • @yangthomas5721
    @yangthomas5721 Před 3 měsíci

    Nice video

  • @Rohitkumar-ks9io
    @Rohitkumar-ks9io Před 4 lety

    Please provide a problem link related to this algorithm . you can provide it in description for further videos.

  • @yangthomas5721
    @yangthomas5721 Před 3 měsíci

    There is a little bug in the code, the --k step after expansion is mandatory.

  • @arghyadeepmandal4458
    @arghyadeepmandal4458 Před rokem

    Really good video 🙂🙂🙂

  • @sahilsharma2952
    @sahilsharma2952 Před 4 lety +1

    Can you make a video on sweep line algo as a whole?

    • @fluentalgorithms4847
      @fluentalgorithms4847  Před 4 lety

      I'll consider it. For now you can refer www.topcoder.com/community/competitive-programming/tutorials/line-sweep-algorithms/

  • @liupeng7757
    @liupeng7757 Před 3 lety

    great!

  • @RAJPATEL-nm9nz
    @RAJPATEL-nm9nz Před 4 lety

    Only one doubt why you have written, If(s[i-k]!=s[i+k]) --k

  • @GaonkaEngineer123
    @GaonkaEngineer123 Před 2 lety

    Best !!!!!!

  • @lokeshkoliparthi9268
    @lokeshkoliparthi9268 Před 4 lety

    I want to ask one thing that does this code only work for showing odd length substrings or will it work for showing even length palindromic substrings also.
    I tried for the string "bbbb" on this code and this code is not working.
    After seeing many videos, I finally understood Manacher's algorithm seeing this video. Thanks a lot and hoping to see more videos from this channel like this.
    Edit:
    One more thing I would like ask is this condition
    if(S[i-k]!=s[i+k]) required as I am facing problem with that line of code and finally removed and your code is running perfect for finding odd palindromes only.
    Once again Thanks for amazing explanation of concept.

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

    Case 2 shown during 13:13 is wrong. p[i] >= p[i'] could be false, the palindrome centered in s_i' could extend back far beyond s_l. The conclusion that p[i] must be greater or equal to r-i is right, however.

    • @siddharthabhi8704
      @siddharthabhi8704 Před 2 měsíci

      Yes, Case 2 is wrong, zxaxz#zxaxp , where i = index of 2nd a

  • @vinaykirpalani5804
    @vinaykirpalani5804 Před 3 lety

    brilliant explanation sir ! , thanks a lot

  • @raj1307
    @raj1307 Před 4 lety

    Can u make a solution video for the PALIN3 problem .. I am unable to understand the precomputation required in it... thanks

    • @fluentalgorithms4847
      @fluentalgorithms4847  Před 4 lety

      You can checkout my explanation here : discuss.codechef.com/t/palin3-editorial/4906/6?u=vedhant

    • @raj1307
      @raj1307 Před 4 lety

      @@fluentalgorithms4847 " To find ans[i], ans[i] = cnt[i+k][s[i]%3] - cnt[i][s[i]%3] will not work because sum[i] would have contributed to the sum right of I "
      Can u pls explain this line once? thanks

    • @fluentalgorithms4847
      @fluentalgorithms4847  Před 4 lety

      I have updated my explanation here : discuss.codechef.com/t/palin3-editorial/4906/6?u=vedhant

    • @raj1307
      @raj1307 Před 4 lety

      @@fluentalgorithms4847 Thanks a lot ... finally understood :)

  • @laraibanwar1618
    @laraibanwar1618 Před 3 lety

    Brother why did u leave making videos.
    They are all exceptional..

    • @laraibanwar1618
      @laraibanwar1618 Před 3 lety

      I will even subscribe ur channel.now
      Plz keep on uoloading

  • @tekbssync5727
    @tekbssync5727 Před 3 lety

    bhai pseodo code link wagera de diya karo

  • @ankurrohilla4655
    @ankurrohilla4655 Před 3 lety

    ❤❤❤

  • @gauravswain6907
    @gauravswain6907 Před 2 lety

    can not understand the psudo code in over 2 times watching this, I am ok with O(n)2.

  • @aishwaryarastogi7265
    @aishwaryarastogi7265 Před 3 lety

    I think the algorithm will fail for a test case such as "cbbd"....

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

    //c++ code
    class Solution {

    public:
    string getModifiedString(string s, int n){
    string sb="";
    for(int i = 0; i < n; i++){
    sb.append("#");
    sb+=s[i];
    }
    sb.append("#");
    return sb;
    }
    public:
    string longestPalindrome(string s1) {
    int m=s1.size();
    string s=getModifiedString(s1,m);// expand the string for even expansion of string
    cout

  • @arshdeepkumar2586
    @arshdeepkumar2586 Před 4 lety

    Great video, but try to make video at max 10 minutes it will help to retain viewers, because everyone is searching for solution in short time.