Solving problems involving permutation