2800. Shortest String That Contains Three Strings
Greedy maybe
Since only a, b, c 3 string, just make permutations and try out all the result
class Solution:
def minimumString(self, a: str, b: str, c: str) -> str:
res = []
def merge(s1, s2):
for i in range(len(s1)):
if s1[i] == s2[0] and s1[i:i+len(s2)] == s2[:len(s1) - i]:
return s1 + s2[len(s1) - i:]
return s1 + s2
for x in permutations([0,1,2], 3):
current = ''
for n in x:
nxt = { 0: a, 1: b, 2: c}[n]
current = merge(current, nxt)
res.append(current)
res.sort(key=lambda x: (len(x), x))
return res[0]