271. Shortest Superstring II
You are given two strings, s1 and s2. Return the shortest possible string that contains both s1 and s2 as substrings. If there are multiple valid answers, return the smallest of them.
A substring is a contiguous sequence of characters within a string.
Example 1:
Input:Â s1 = "aba", s2 = "bab"
Output:Â "abab"
Explanation:
"abab" is the shortest string that contains both "aba" and "bab" as substrings.
Example 2:
Input:Â s1 = "aa", s2 = "aaa"
Output:Â "aaa"
Explanation:
"aa" is already contained within "aaa", so the shortest superstring is "aaa".
Now Your Turn!
Pick the correct output for the given inputInput: s1 = "a", s2 = "b"
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= s1.length <= 100
- 1 <= s2.length <= 100
- s1 and s2 consist of lowercase English letters only.