Solution for unique permutation