Answer to Question #256943 in Python for Raju

Question #256943

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


1
Expert's answer
2021-10-31T12:01:09-0400
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))

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