Professional Documents
Culture Documents
Input Format
Read a string
Output Format
Example
If the input is "babad", the output should be 3 because the longest palindrome substring
is "bab" or "aba", whose length is 3.
CODE:
def lps_length(s: str) -> int:
if not s:
return 0
n = len(s)
dp = [[False] * n for _ in range(n)]
max_length = 1
for i in range(n):
dp[i][i] = True
for i in range(n - 1):
if s[i] == s[i + 1]:
dp[i][i + 1] = True
max_length = 2
return max_length
string = input()
result = lps_length(string)
print(result)
OUTPUT: