Longest Palindromic Substring O(N) Manacher's Algorithm | Leetcode - 5

preview_player
Показать описание

Given a string, find the longest palindromic substring in this string in linear time.

To support us you can donate

Check out our other popular playlists:

If you find any difficulty or have any query then do COMMENT below. PLEASE help our channel by SUBSCRIBING and LIKE our video if you found it helpful.

#coding #leetcode #programminglife #programmingisfun #programmer #tech #software #codinglife #leetcode
Рекомендации по теме
Комментарии
Автор

We hope you all are enjoying our videos!!! Don't forget to leave a comment!!! Please like the video to support us!!!

Questions you might like:

Struggling in a question??

Leave in a comment and we will make a video!!!🙂🙂🙂

AlgorithmsMadeEasy
Автор

At times I wonder why learn this algorithm. I don't know why I need to find a palindrome at work.

Kidkromechan
Автор

At 6:38, how did P[mirror] become zero? p[mirror] was 2 before it and r-i should be 1, right?

manumathew
Автор

12:37 umm where did you define this variable r???

anonymousperson
Автор

Thank you sir for precious explanation

kanhamishra
Автор

is it good to use this approach in interview? or we can leave this problem till O(Nsquare) time complexity?

sumit_verma
Автор

Very Clear Explaination Via That Left And Right Pointer .. Thanks

TheIndianChroniclee
Автор

public String longestPalindrome(String s)
{
int n=s.length();
char[] newStr=new char[2*n+1];
int i=0;
newStr[i++]='#';
for(char c:s.toCharArray())
{
newStr[i++]=c;
newStr[i++]='#';
}
int p[]=new int[2*n+1];
int center=0, right=0;
int longestLenght=0, longestCenter=0;
for (i = 0; i <newStr.length; i++)
{
int mirror=2*center-i;
if(right>i)
{
p[i]=Math.min(p[mirror], right-i);
}
int a=i+(p[i]+1);
int b=i-(p[i]+1);


{
b--;
a++;
p[i]++;
}
if(p[i]>=longestLenght)
{
longestCenter=i;
longestLenght=p[i];
}
if(i+p[i]>right)
{
center=i;
right=i+p[i];
}
}
String st=new String(newStr);
return st.substring(longestCenter-longestLenght, longestCenter+longestLenght).replace("#", "");
}

AmritAgarwal
Автор

how did u get it. why are you starting off in the middle?

abhigyanraha
Автор

Hi sir the git link which you provided it is not working got "not found"
The way of explanation is awesome.

skfiroz
Автор

remove line no 11 ===>newStr[i]='#';

AmritAgarwal
Автор

Sir i can not understand with are you saying, maybe talk slower. India accent is indeed on another level.

TLDZ-sm
Автор

pehle ek acha sa mic khareed lo uske baad gyaan baatna

jatinbhatoya
welcome to shbcf.ru