solution for next permutation