Answer to Question #233200 in Python for rasi

Question #233200

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.


1
Expert's answer
2021-09-04T15:22:58-0400
def check_overlapping(first, second):
    answer = ""
    first_length = len(first)
    second_length = len(second)
    for i in range(first_length):
        overlap = ""
        for j in range(second_length):
            if i + j < first_length \
                    and first[i + j] == second[j]:
                overlap += second[j]
                if i + j == first_length - 1 \
                        and len(overlap) > len(answer):
                    answer = overlap
            else:
                break
    if answer != '':
        return answer
    else:
        return 'No overlapping'


A = input()
B = input()

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