Concept Flow - Next Permutation of Array
Start from right end
Find first i where nums[i
Yes
Find j from right where nums[j
Swap nums[i
Reverse nums[i+1:
Done
No
Reverse whole array (last permutation)
Find the first decreasing element from right, swap it with a just larger element on right, then reverse the suffix to get the next permutation.
