You wish to concatenate two strings by overlaping the end of the first string and the start of the second string by the minimum distance that they match?
Hmmm... Too me it looks like: Match as much as possible but if there are more matches, take the 2nd best match.