Imagine you're tasked with creating the shortest possible string that contains three given strings as substrings. This is a classic string manipulation problem that tests your understanding of string overlap and optimization.
Given three strings a, b, and c, you need to find a string with minimum length that contains all three strings as substrings. The key insight is that strings can overlap - for example, if you have "abc" and "bcd", you can combine them as "abcd" instead of "abcbcd".
If multiple strings have the same minimum length, return the lexicographically smallest one (the one that would appear first in dictionary order).
Example: If a = "abc", b = "bcd", and c = "def", one possible answer is "abcdef", but we need to check all possible arrangements to find the shortest.
Input & Output
Visualization
Time & Space Complexity
6 permutations ร O(nยฒ) for each merge operation where n is the average string length
Space for storing the result strings and temporary merged strings
Constraints
- 1 โค length of each string โค 1000
- All strings contain only lowercase English letters
- Each string is non-empty
- The total number of possible arrangements is small (6)