Answer to Question #235072 in Python for kaavya

Question #235072

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.

Sample Input 1

ramisgood

goodforall

Sample Output 1

good

Sample Input 2

finally

restforall

Sample Output 2

No overlapping




1
Expert's answer
2021-09-11T23:39:22-0400
A = input("Enter the first string:")
B = input("Enter the second string: ")


def overlapping(S1, S2):
    output = ""
    lenght1, lenght2 = len(S1), len(S2)
    for i in range(lenght1):
        match = ""
        for n in range(lenght2):
            if (i + n < lenght1 and S1[i + n] == S2[n]):
                match += S2[n]
            else:
                if (len(match) > len(output)): output = match
                match = ""
    if output == '':
        return 'No overlapping'
    else:
        return output


print(overlapping(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