You are given two strings, str1 and str2. Write a function that merges them into a single string by identifying the longest substring that appears at the end of str1 and at the beginning of str2. The merged result should concatenate the two strings, using that overlapping substring only once.
Constraints:
1 ≤ str1.length, str2.length ≤ 10^5Example 1:
str1 = "hello", str2 = "loworld"
"helloworld"
The longest suffix of "hello" that is also a prefix of "loworld" is "lo". Overlapping them produces "helloworld".
Example 2:
str1 = "abc", str2 = "abcdef"
"abcdef"
The entire string "abc" is a suffix of str1 and a prefix of str2. Merging yields "abcdef".
Example 3:
str1 = "abc", str2 = "xyz"
"abcxyz"
No common suffix-prefix substring exists, so the strings are simply concatenated to "abcxyz".