Answer to Question #165110 in Python for ravi

Question #165110

Prefix Suffix

Write a program to check the overlapping of one string's suffix with the prefix of another string.Input


The first line of the input will contain a string A.

The second line of the input will contain a string B.Output


The output should contain overlapping word if present else print "No overlapping".Explanation


For example, if the given two strings, A and B, are "ramisgood" "goodforall"

The output should be "good" as good overlaps as a suffix of the first string and prefix of next.



input

ramisgood

goodforall


ouput

good


input-2

finally

restforall


output:

No overlapping


1
Expert's answer
2021-02-22T16:07:50-0500
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

Laxman Godishala
16.01.23, 15:41

Super

Assignment Expert
17.03.21, 08:54

Dear teja Questions in this section are answered for free. We work on all questions and publish answers after verification. There is no guarantee of answering certain question but we are doing our best. Although if you have serious assignment that requires large amount of work and hence cannot be done for free you can submit it as assignment and our experts will surely assist you.

teja
17.03.21, 08:52

Thank a lot for your code!!! But one test case is not passing. For example, given two strings are : "correct" "wrong" Here the output should be "No Overlapping" but its printing "r" can you please correct the code and mail me please.

Akhil
06.03.21, 07:57

Thank a lot for your code!!! But one test case is not passing. For example, given two strings are : "correct" "wrong" Here the output should be "No Overlapping" but its printing "r" can you please correct the code and mail me please...

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS