Answer to Question #284053 in Python for Rishu

Question #284053

Given a string S, find the longest palindromic substring in S. Substring of string S: S[ i....j] where 0 sisj< len(S). Palindrome string: A string which reads the same backwards. More formally, S is palindrome if reverse(S) =S. Incase of conflict, return the substring which occurs first ( with the least %3D starting index).


1
Expert's answer
2022-01-02T02:23:37-0500
def longest_poly(s):
	start = 0
	l = len(s)
	while start < l:
		for i in range(len(s)-l):
			tmp = s[start+i:start+i+l]
			if tmp == tmp[::-1]:
				return tmp
		l -= 1
	return -1
print(longest_poly("abcdcbd"))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS