This question already has an answer here:
- Finding “sub-palindromes”. 31 answers
A palindrome is a string which is the same when read forwards and backwards. For example "racecar" is a palindrome, but "Racecar" is not. A substring is a contiguous set of characters in a larger string. Your task is to write a program or method which takes a string or character array as input and outputs the length of the longest substring of that string which is a palindrome.
This is because "anana" is a 5 character substring of "banana"
This is because both "aca" and "ada" are 3 characters.
This string has no palindromes that are more than 1 character.
If the input is the empty string the output must be 0.
This is code-golf so the shortest submission in any language wins.
Note: There have been slight variations of this question in the past, which have all had wording issues or been asking a variation of this question. You can see these:
Finding "sub-palindromes". - The purpose of this challenge is to print all palindromic substring, rather than the length of the longest. As such many of the answers to this question do not have close analogues.