Merge Strings on Edge Overlap

Asked at Apple

Reported by the problem's creator, not verified

Import another question

You are given a function that joins two strings, dropping the part where the end of one matches the start of the other.

Examples

  1. Example 1

    Input: str1 = hello wor, str2 = world peace

    Output: hello world peace

    Explanation: The last 3 characters of hello wor are wor, which are also the first 3 of world peace, so the overlap for (str1, str2) is 3. The overlap for (str2, str1) is 0, so the first order wins and world peace is added without its first 3 characters.

  2. Example 2

    Input: str1 = ca, str2 = ac

    Output: cac

    Explanation: Merging (str1, str2) overlaps on a and gives cac; merging (str2, str1) overlaps on c and gives aca. Both overlaps are 1, so the tie rule keeps the first order and the result is cac.

Import your own questions
Paste a question you were asked and get a full problem: statement, tests and a checked solution.
Import a question

Code

Loading editor…

Ln 1, Col 1

Start an attempt to use Coach.