I'm having trouble explaining because English is my second language and I'm bad at logic. I'll give examples to help.
If letters are ABC, the valid combinations I'm looking for are AB,AC,BA,BC,CA,CB. Simply combined into a string: ABACBABCCACB But there are still duplicates in that string. If I "compress" it, I get: ABACBCA
I'm not sure how to explain better, but I'm looking for an algorithm that would produce the "compressed" version.