Tell me the error in my code. why test case are passing

int* nextPermutation(int* A, int n1, int *len1)
{
int k=-1,i,j,temp;
int arr=(int) malloc(n1 * sizeof(int));
for(i=0;i<n1-1;i++)
{
if(A[i]<A[i+1])
{
k=i;
}
}
*len1=n1;
if(k==-1)
{
for (i = 0; i < n1-1; i++)
{
for (j = 0; j < n1-i-1; j++)
{
if (A[j] > A[j+1])
{
temp=A[j];
A[j]=A[j+1];
A[j+1]=temp;
}
}
}
}
int l;
for(i=k+1;i<n1;i++)
{
if(A[i]>A[k])
l=i;
}
temp=A[k];
A[k]=A[l];
A[l]=temp;
int start=k+1;
int end=n1-1;
while (start < end)
{
temp = A[start];
A[start] = A[end];
A[end] = temp;
start++;
end–;
}
for(i=0;i<n1;i++)
{
arr[i]=A[i];
}
// printf("%d %d ",A[n1-2],A[n1-1]);
return arr;
}

Click here to start solving coding interview questions