Search for the longest palindrome in a string
PHP
Medium
strings
Task «Search for the longest palindrome in a string»
Write a function that takes a string and finds the longest palindromic substring. If there are several, return the first one in order. The string consists only of lowercase Latin letters. The string length is from 1 to 1000 characters. Implement an algorithm with a time complexity of O(n^2) or better.
Input Format
One line containing an arbitrary sequence of lowercase Latin letters.
Output Format
One line — the longest palindromic substring. If there are no palindromes, output an empty string.
Examples
Example 1
INPUT
babad
OUTPUT
bab
Example 2
INPUT
abbae
OUTPUT
abba
Example 3
INPUT
a
OUTPUT
a
main.php