Build permutations by choosing an unused element at each position.
Backtrack with a used[] array. When path length equals n, record it.
Each recursion level selects one distinct element for the next position, generating all n! orderings.
Build permutations by choosing an unused element at each position.
Backtrack with a used[] array. When path length equals n, record it.
Each recursion level selects one distinct element for the next position, generating all n! orderings.