Merge Strings on Edge Overlap
Asked at Apple
Reported by the problem's creator, not verified
You are given a function that joins two strings, dropping the part where the end of one matches the start of the other.
Examples
Example 1
Input: str1 =
hello wor, str2 =world peaceOutput:
hello world peaceExplanation: The last 3 characters of
hello worarewor, which are also the first 3 ofworld peace, so the overlap for(str1, str2)is 3. The overlap for(str2, str1)is 0, so the first order wins andworld peaceis added without its first 3 characters.Example 2
Input: str1 =
ca, str2 =acOutput:
cacExplanation: Merging
(str1, str2)overlaps onaand givescac; merging(str2, str1)overlaps oncand givesaca. Both overlaps are 1, so the tie rule keeps the first order and the result iscac.