Need Help to solve this Runtime error *** Error in `./solution': double free or corruption (out): 0x00000000025ab010 *** Aborted

vector Solution::nextPermutation(vector &A){
int n=A.size();
if(A[n-2]<A[n-1]){
swap(A[n-2],A[n-1]);
return A;
}
else{
int i=n-2;
while(i>0&&A[i-1]>=A[i]){
i–;
}
if(i==0){
sort(A.begin(),A.end());
return A;
}
swap(A[i],A[i-1]);
sort(A.begin()+i,A.end());
return A;
}
}

If your A.size() gives 1 then your starting “if statement” fails because it gives if(A[-1]<A[0]) gives a runtime error

Click here to start solving coding interview questions