Next permutation


Pls tell why is t not passing any test cases

hello Sujal,
there is some logical issue in ur code.

pls refer this->
image

Thanks for this algo, can you also please tell why isnt my algo working, as it was passing the sample input, but not the testcases

your code looks fine to me, except for the cases where the array might contain leading zeros(which is not ideally expected).
can you please send me the link of platform where you are submitting your code.

thanks

really sorry. there is a small mistake…
the condition should be
if(arr[i]>=arr[i+1]) //equal sign is important
continue;

updated code: https://ide.codingblocks.com/s/211973

please rate and resolve it if satisfied.
thanks

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.

This problem can be solved just by using two simple algorithms searching and find smaller element in just O(1) extra space and O(nlogn ) time and also easy to implement .

To understand this approach clearly . Watch this Video : https://www.youtube.com/watch?v=DREZ9pb8EQI

3 Likes