java.lang.Object
g2701_2800.s2800_shortest_string_that_contains_three_strings.Solution

public class Solution extends Object
2800 - Shortest String That Contains Three Strings.<p>Medium</p> <p>Given three strings <code>a</code>, <code>b</code>, and <code>c</code>, your task is to find a string that has the <strong>minimum</strong> length and contains all three strings as <strong>substrings</strong>.</p> <p>If there are multiple such strings, return the <strong>lexicographically smallest</strong> one.</p> <p>Return <em>a string denoting the answer to the problem.</em></p> <p><strong>Notes</strong></p> <ul> <li>A string <code>a</code> is <strong>lexicographically smaller</strong> than a string <code>b</code> (of the same length) if in the first position where <code>a</code> and <code>b</code> differ, string <code>a</code> has a letter that appears <strong>earlier</strong> in the alphabet than the corresponding letter in <code>b</code>.</li> <li>A <strong>substring</strong> is a contiguous sequence of characters within a string.</li> </ul> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> a = &ldquo;abc&rdquo;, b = &ldquo;bca&rdquo;, c = &ldquo;aaa&rdquo;</p> <p><strong>Output:</strong> &ldquo;aaabca&rdquo;</p> <p><strong>Explanation:</strong> We show that &ldquo;aaabca&rdquo; contains all the given strings: a = ans[2&hellip;4], b = ans[3..5], c = ans[0..2]. It can be shown that the length of the resulting string would be at least 6 and &ldquo;aaabca&rdquo; is the lexicographically smallest one.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> a = &ldquo;ab&rdquo;, b = &ldquo;ba&rdquo;, c = &ldquo;aba&rdquo;</p> <p><strong>Output:</strong> &ldquo;aba&rdquo;</p> <p><strong>Explanation:</strong> We show that the string &ldquo;aba&rdquo; contains all the given strings: a = ans[0..1], b = ans[1..2], c = ans[0..2]. Since the length of c is 3, the length of the resulting string would be at least 3. It can be shown that &ldquo;aba&rdquo; is the lexicographically smallest one.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= a.length, b.length, c.length <= 100</code></li> <li><code>a</code>, <code>b</code>, <code>c</code> consist only of lowercase English letters.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details