Solution for the Permutation sequence