algorithms – The smallest string containing sets of letters

I am looking for a solution to this problem:
Given several sets of letters (Set0 = {a, b, c, d}, Set1 = {d, e, f, g}, Set2 = {a, b, e, g}, …), what is the minimum length of the string containing all sets. Sets must be present in the form of a single substring, it is possible to duplicate letters in the final string and it is also possible to swap the letters in a set.

For example.:

abc | def | gabe (strlen = 10, sets are like: Set0, Set1, Set2)

Where Set0 starts at index 0, Set1 starts at index 3, Set2 starts at index 7.

Another better solution is:

ab | egf | dabc (strlen = 9, sets are like: Set2, Set1, Set0)

Where Set0 starts at index 5, Set1 starts at index 2, Set2 starts at index 0.