Why my solution doesn't work here if it's works all right in my ubuntu terminal


#1

It says runtime error. But I think my code is O(n).
My code goes here:

void srt(vector &v, int k, int n){
int rep = v[k+1];
int arg = k+1;

for(int j= k+2; j<n; j++){
    
    if((v[j]<rep) && (v[j]>v[k])) arg = j;
    
    
    
    
}

int temp=v[k];
v[k]= v[arg];
v[arg]=temp;
return;

}

vector solution::nextPermutation(vector &A) {
bool a = true;
int n = A.size();
int i;
for(i=n-1; i>=0; i–){
a = a && (A[i]<=A[i-1]);

   if(a==false) break;
    
}

if(a==true) {reverse(A.begin(),A.end()); return A;}

else srt(A, i-1, n-1);
return A;

}