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


Leave a comment

Parsed as Markdown

Login to leave a comment