I just think my code is more self-explained than the editorial python 3

Comment body goes here flag = False
toSwap = 0
for i in range(len(A)-2,-1,-1):
if A[i]<A[i+1] :
flag = True
toSwap = i
break
if not flag:
return sorted(A)
swapWith = 0
for i in range(toSwap+1,len(A)):
if A[i]>A[toSwap]:
swapWith = i
A[swapWith],A[toSwap]=A[toSwap],A[swapWith]
A[toSwap+1:]=reversed(A[toSwap+1:])
return A

Click here to start solving coding interview questions