The question is actually more difficult than we think. Because we need to generate exactly the next lexicographically number.

From the wiki, we know that in order to generate that, we need to do the following:

- Find the largest index i s.t. nums[i] < nums[i + 1]
- Find the largest index j after i s.t. nums[j] > nums[i]
- swap nums[i] and nums[j]
- reverse i + 1 to n - 1 of vector/array nums

It is very tricky, which I thought it cannot give a correct one in 60 mins, just remember it and hope it won’t be asked in the interview.