This algorithm take nlogn time-complexity
There are multiple algorithm available for calculating longest SubString Palindrome. Manacher's Algorithm is known fastest one which takes n time-complexity, However practically above PalLong.java faster if we check comparison based
For string wpwasdfgasdfghgfdsagfdsaojd :
Manacher's Algorithm takes 165 operational process and takes 33290826ns
While PalLong Algorithm which written by me takes 60 operational process and takes 68423368ns
Logic behind the Algorithm is to check palindrome string for given position
for(int i =0 ; i < str.length()-2; i++){
pal1= "" +str.charAt(i+1);
pal1 = isPalindrome(str, i, nxt, pal1, cnt);
if(max<=pal1.length()){
max = pal1.length();
longPal1 = pal1;
}
pal1 = "";
}
Recursively checking longest possible palindrome for given string
public static String isPalindrome(String str, int start, int end, String pal){
if(start == 0 || end == str.length())
return str.charAt(start) + "" + pal + str.charAt(end);
else if (str.charAt(start) == str.charAt(end)) {
pal = str.charAt(start) + "" + pal + str.charAt(end);
return isPalindrome(str, start-1, end+1, pal);
}
else return pal;
}