Merge words by overlapping suffix and prefix

Given two words w1 and w2, merge them into one word by overlapping the suffix of the first word and the prefix of the second word. If there's nothing to concatenate, return the concatenation of the words.

Example

For w1 = "cesario" and w2 = "oputera", the output should be
 "cesarioputera".

IN

aab
bbc

OUT

aabbc

IN

qwer
tyuio

OUT

qwertyuio

IN

abcd
bcdty

OUT

abcdty

IN

nothing
thing

OUT

nothing

IN

cesario
oputera

OUT

cesarioputera
Login to submit solution


75 symbols python3 failed test 1 Code error

Traceback (most recent call last): File "./code", line 3, in <module> I(r) EOFError: EOF when reading a line

Sun Jun 4 03:12:51 2017 Sait2000
I=input;a=I();b=I();r=i=0;
while not r:r=a[:i]+b;r*=r[:len(a)]==a;i+=1
I(r)
70 symbols python3 failed test 1 Wrong answer
bc
instead of
aabbc
Mon Jun 5 15:29:52 2017 bugov
a=input()
b=input()
i=0
while a[-i-1]==b[i]:i+=1
print(a[:-i-2]+b[i:])

View all solutions