Help JNEXT

help
jnext
spoj
wa

#1

I am trying to solve this but i am getting WA everytime. I have used the next_permutation as well as the
algorithm but still am getting WA…Help…!!!

link to the question : http://www.spoj.com/problems/JNEXT/
link to my answer : https://ideone.com/uH0ujN


#2

This is your Ac solution: https://ide.geeksforgeeks.org/OgWyqez21V
You were actually printing the function also which caused an additional 0 to be appended to the ans.


#3

Don’t use next permute. it will give a wrong answer in the test case 1
5
5 4 3 0 1
as the function “next permutation” gives the lexicographically next permutation. but will not work on this case. You can just apply a for loop in reverse and check for any element where a* > a[i-1], swap these two and sort from i to n. this will give you your required result.

Regards.


#4

help please, my solution is giving WA: https://ideone.com/6j9k6S


#5

Getting Wrong Answer, please help!

Thanks in advance!


#6

Why would it not work.

The ans for this would be 1554310 which is right i guess.


#7

Thanks it worked…!!