Character Sequence Merge

I have a problem and I need an algorithm to solve it.
I could not find it, and I do not know if the problem is NP-Hard.

The problem is this: I have multiple character sequences. I want to combine them into one sequence, which includes all the characters of the original sequences, preserving the original character order. Duplicate characters that come from different sequences must be removed. The resulting sequence should be the smallest possible.

If one of the sequences is "abc", the resulting sequence must be * a * b * c *, where * is a sequence of 0 or more characters. If the input sequences are "abc" and "cba", the output must be "abcba", "c" is included once and the * a * b * c * and * c * b * a * property are saved.

An example :

Input:

abcde
xbcaf
axdaf

Combination Method:

a-bcde--
-xbc--af
ax--d-af

Conclusion:

axbcdeaf

Multiple outputs are possible, "abcd" and "cba" will result in "abcdba", "abcbda" or "abcbad". I will need only one output, any output is valid if its length is the smallest possible length.

thank

+5
source share
1 answer

All Articles