Solution for permutation