Concept Flow - Next Permutation of Array
Start from right end
Find first pair where nums[i
If no such pair, reverse whole array -> Done
Yes
Find element nums[j
Swap nums[i
Reverse subarray from i+1 to end
Done with next permutation
Find the next lexicographically greater permutation by locating a pivot, swapping, and reversing the suffix.
