Answer to Question #228741 in Python for kaavya

Question #228741

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-08-25T05:47:17-0400
def overlapping(str1, str2):
    n1 = len(str1)
    n2 = len(str2)
    n = n1 if n1 < n2 else n2
    res = ''
    for i in range(1,n+1):
        if str1[n1-i:] == str2[:i]:
            res = str1[n1-i:]
    return res

def main():
    str1 = input()
    str2 = input()
    res = overlapping(str1, str2)
    if not res:
        print('No overlapping')
    else:
        print(res)

main()

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