Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers. If such arrangement is not possible, it must rearrange it as the lowest possible ...
# Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. # You must write an algorithm that runs in O(n) time and uses O(1) extra space.