I have submitted following code for the Longest Palindrome problem:
def isPalin(s):
if s == s[::-1]:
return True
else:
return False
def getResult(n, s):
for l in range(n, 0, -1):
for i in range(n-l+1):
if isPalin(s[i:i+l]):
print(len(s[i:i+l]), s[i:i+l], sep='\n')
return
n = int(input().strip())
s = input().strip()
getResult(n, s)
But, this is a basic approach and can be optimized further to improve execution time. Kindly help.