Longest Palindrome Sub String Length

Posted on December 30, 2014 by

Program to compute length of longest sub string which is palindrome.

Example: If given string is 'ohello' then we can form palindromes like 'lel', 'olo', 'olelo'.. etc, among them the largest substring is of length 5.


def maxPalindromeSubStringLen(str):
	leng = 0
	ext = 0
			leng = leng + (str.count(str[0]))
			leng = leng + (str.count(str[0])) - 1
			ext = 1
		str = str.replace(str[0],"")
	return leng + ext
if __name__=="__main__":
	print("Enter a string: ", end="")
	paragraph = input()
	print("Length of longest palidrome ::", maxPalindromeSubStringLen(paragraph))

Fork Download

This website is made possible by displaying online advertisements to our visitors.
Please consider supporting by disabling your ad blocker.
loading comments...