Concept Flow - Next Permutation of Array
Start from right end
Find first pair i where nums[i
Yes
Find j from right where nums[j
Swap nums[i
Reverse subarray from i+1 to end
Done - next permutation found
No
Reverse whole array - last permutation reached
Find the next bigger arrangement by swapping and reversing parts of the array starting from the right.