Showing right answer in test custom, but runtime error while submission

help
`int Solution::removeDuplicates(vector &A) {
int n=A.size();
if(n==1)
return 1;
int ct=0;
int cur=0;
for(int i=0;i<A.size()-1-ct;i++)
{
int j=i+1;

    while(A[j++]==A[i]);
    
    j-=2;
    
    if(j==i)
        cur++;
    
    else
    {
        cur++;
        ct+=j-i;
        //cout<<"ct="<<ct<<" ";
        for(int k=0;k<A.size()-ct+1;k++)
            A[k+i+1]=A[j+k+1];
    }
}
//cout<<cur<<" ";
return cur;
// Do not write main() function.
// Do not read input, instead use the arguments to the function.
// Do not print the output, instead return values as specified
// Still have a doubt. Checkout www.interviewbit.com/pages/sample_codes/ for more details

}
`

Click here to start solving coding interview questions