first, second and third. Build the shortest string that contains each of them as a substring (a contiguous piece).
If several strings of that minimal length exist, return the one that comes first alphabetically (the lexicographically smallest).
The pieces may overlap: "cat" and "tea" fit into "catea", and a string that already sits entirely inside another one needs no extra room.first="cat", second="tea", third="eat" → 'cateat'
"cat" and "tea" share the letter t, giving "catea"; appending t gives "cateat", which also contains "eat". Nothing shorter than 6 letters works.
first="ab", second="b", third="ba" → 'aba'
"aba" contains all three strings, and two letters cannot hold both "ab" and "ba".
first="z", second="y", third="x" → 'xyz'
No letters overlap, so any arrangement of the three letters has length 3; the alphabetically smallest is "xyz".
first="cat", second="tea", third="eat"
'cateat'
Run checks the first 3 tests in your browser. Submit checks all 114 tests on the server, hidden ones included.