My code for next permutations is not accepting the test cases

hello @raginibhayana99
ur algorithm is bit wrong.
u dont have to swap a[i] with a[i+1] .

refer this->
Algorithm The steps to solve this problem:

  • Scan from right to left, find the first element that is less than its previous one.
4 5 6 3 2 1 
  |
  p
  • Scan from right to left, find the first element that is greater than p.
4 5 6 3 2 1 
    |
    q
  • Swap p and q
4 5 6 3 2 1 
swap
4 6 5 3 2 1 
  • Reverse elements [p+1, nums.length]
4 6 1 2 3 5

my test cases still arent passing, i have updated the code in the link

pls share the updated code link with me.

it is the same link as the previous code’s link

439004 ide coding blocks

its showing ur old code only.
after updating ur code , u need to save it again to get new link

check now->

1 Like

thank you so much, it works now!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.