Whats wrong with this code,Iam getting right answer in my IDE,but for the same test case wrong answer here


#1

A : [ 839, 776, 843, 422, 252, 385, 543, 94, 711, 636, 517, 257, 222 ]

vector Solution::nextPermutation(vector &A) {

if(A.size() < 2) 
    return A;

bool swapped=false;

for(int i=A.size()-1;i>=0;i--)
{
    if(A[i-1]<A[i])
    {
     swap(A[i-1],A[A.size()-1]);
     reverse(A.begin()+i,A.end());
     swapped=true;
     break;
    }
}
if(!swapped)
{
    sort(A.begin(),A.end());
    return A;
}

return A;

}


#2

your swap logic is wrong