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


15 symbols pyth
Sun Jun 4 03:04:20 2017 Sait2000
Jwhf}z._T+RJ._z
16 symbols pyth
Sun Jun 4 02:57:01 2017 Sait2000
Jw+hf}z._+TJ._zJ
17 symbols pyth
Sun Jun 4 02:54:12 2017 Sait2000
Jw+hfq<+TJlzz._zJ
19 symbols pyth
Sun Jun 4 02:53:47 2017 Sait2000
Jw+hfq<+TJlzz+k._zJ
79 symbols python3
Sun Jun 4 03:11:15 2017 Sait2000
a=input();b=input();r=i=0;
while not r:r=a[:i]+b;r*=r[:len(a)]==a;i+=1
print(r)

View all solutions