Answer to Question #255832 in Python for Chethan

Question #255832
Write a program to check the overlapping of one string's suffix with the prefix of another strings Explanation: for example if the given string A and B are "ramisgood", "goodforall" The output should be "good" as overlaps as a suffix of the first string and prefix of next Sample input 1 ramisgood goodforall Sample output 1 good Sample input 2 Finally Restforall Sample output 2 No overlapping
1
Expert's answer
2021-10-29T15:21:40-0400
a = 'ramisgood'
b = 'goodforall'

c = 'finally'
d = 'restforall'


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))
print(longestSubstringFinder(c, d))

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