 # The test case that gave Runtime error when I clicked Test passed and gave correct ans as custom input!?

#1

How is this possible.
below is the testcase
25
251 844 767 778 658 337 10 252 632 262 707 506 701 475 410 696 631 903 516 149 344 101 42 891 991

#2

Same problem…
Interview Bit committee please look forward to it.

#3

Yes, same problem for me too. Please look into it.

#4

Exact same issue here.

#5

I think the problem might not be in that particular test case 'cause I was facing a similar problem but then, I realised, I didn’t handle the case when the first decreasing point doesn’t exist so it will be -1 thus throwing run-time error…maybe it’s the compiler issue…it should provide the first test case where the error exists.

``````vector<int> Solution::nextPermutation(vector<int> &A) {
int n=A.size();

int i=n-1;
while(i>=0 && A[i]<=A[i-1])
i--;
int pos=i-1;
if(pos>=0) //I just included this if statement and that's it
{
i=n-1;
while(A[i]<=A[pos]) i--;
swap(A[i],A[pos]);
}
reverse(A.begin()+pos+1,A.end());
return A;
}

``````

#6

I am facing the same issue. Please look into this

#7

thanks bro…you are right

#8

I was facing same problem, till i tried this

vector Solution::nextPermutation(vector &A) {
int len = A.size();
if(len==1) {return A;}
int i, k;
bool changes = false;
// A : [ 839, 776, 843, 422, 252, 385, 543, 94, 711, 636, 517, 257, 222 ]
// 839 776 843 422 252 385 543 222 94 257 517 636 711
for(i=len-2; i>=0; i–) {
if(A[i]<A[i+1]) {
changes = true;
break;
}
}
if(changes == true) {
for(k=len-1; k>i; k–) {
if(A[i]<A[k]) {
break;
}
}
swap(A[i], A[k]);
reverse(A.begin()+i+1,A.end());
} else {
reverse(A.begin(),A.end());
}
return A;
}