Problem Statement: here

PS Understanding:
We have to find the arrangement of numbers that is immediately bigger than the current one.

Solution:



def nextPermutation(nums):
n = len(nums)

i = n - 2
while i >= 0 and nums[i] >= nums[i + 1]:
i -= 1

if i >= 0:
...