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