Input: string = "abcab", n = 10 Output: aabbc aabcb aacbb ababc abacb abbac abbca abcab abcba acabb Input: string = "okok", n = 4 Output: kkoo koko kook okko
Python provides a built-in method for finding permutations of any given sequence that is present in the
itertools package. But this method does not provide unique permutations. Therefore, to ensure that any permutation does not repeat, we use a set and meet the following conditions:
- If the permutation is not present in the set, print it and paste it into the set. Increase the number of unique permutations.
- Otherwise, go to the next permutation.
Below is the implementation of the above approach:
aabbc aabcb aacbb ababc abacb abbac abbca abcab abcba acabb