Write a Python function that takes a string as input and returns the length of the longest palindromic substring within the string
Write a Python function that takes a string as input and returns the length of the longest palindromic substring within the string
![](/static/compass_v2/shared-icons/check-mark.png)
Step by step
Solved in 3 steps with 1 images
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Thank you but it does not the lemgth of the string. I want the out as len(aabbaa)
What could have wrong with my code below?
### START FUNCTION
def longest(s:str)->str: # The desired function,
n = len(s)
st = 0
maxi = 0
start = 0
dicti = {} # The desired function.
dicti[s[0]] = 0
for i in range(1, n):
if s[i] not in dicti:
dicti[s[i]] = i
else:
if dicti[s[i]] >= st: # Checking for the current and maxlength.
curi = i - st
if maxi < curi:
maxi = curi
start = st
st = dicti[s[i]] + 1
dicti[s[i]] = i
if maxi < i - st:
maxi = i - st
start = st
return s[start : start + maxi] # Maximum lenngth substing.
#print(longest("aabbaababa"))
### END FUNCTION
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)