Skip to content

Instantly share code, notes, and snippets.

@CraigTheKiwi
Created August 16, 2021 09:46
Show Gist options
  • Save CraigTheKiwi/fec7dfdcccb7ac1b4a555b3b894c0c56 to your computer and use it in GitHub Desktop.
Save CraigTheKiwi/fec7dfdcccb7ac1b4a555b3b894c0c56 to your computer and use it in GitHub Desktop.
Solution for Cassidoo Newsletter (Aug 16)
#!/bin/python3
def checkPal(string, i, j):
length = j-i+1
while string[i] == string[j] and i <= j:
# 5 , 6
i+=1
j-=1
# 6 , 5
if i == j or i + 1 == j:
# False or 7 == 5 > False
return length
return 0
def pSubstring(string):
count = 0
len_string = len(string)
for i in range(len_string):
for j in range(len_string-1, i, -1):
if string[i] == string[j] and j-i != len_string-1:
test = checkPal(string, i, j)
if test > count:
count = test
return count
print(pSubstring('babad'),3)
print(pSubstring('dabada'), 5)
print(pSubstring('aawbababaawa'), 5)
print(pSubstring('qdabbadw'), 6)
print(pSubstring('aaaxxyyxx'), 6)
print(pSubstring('aaaxxyyxxbbbxxxyxxx'), 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment