Solved next permutation problem.