Given a text T and a set of strings S (where the combined length of strings in S equals the length of T), find the most efficient sequence of swaps to apply to T so that all of the substrings in S appear exactly in T, where non-adjacent swaps are allowed. The characters in T will always be unique and will always have a corresponding character in S.
For example:
T = "ABCDE"
S = {"CB", "EDA"}
the desired resulting string could be either "CBEDA" or "EDACB" (whichever can be achieved with fewer swaps). One way to solve this case would be:
"ABCDE". swap A and C: "CBADE". swap A and E: "CBEDA".