solve next permutation problem.