Prefix suffix
Write a program to check the overlapping of one string's suffix with the prefix of another string.
Sample Input 1
ramisgood
goodforall
Sample output 1
good
Sample Input 2
finally
restforall
Sample Input 2
No overlapping
a = input()
b = input()
def longestSubstringFinder(string1, string2):
answer = ""
len1, len2 = len(string1), len(string2)
for i in range(len1):
match = ""
for j in range(len2):
if (i + j < len1 and string1[i + j] == string2[j]):
match += string2[j]
else:
if (len(match) > len(answer)): answer = match
match = ""
if answer == '':
return 'No overlapping'
else:
return answer
print(longestSubstringFinder(a, b))
Comments
Leave a comment