```
class Solution {
public:
int removeDuplicates(int A[], int n)
{
int start=1;
int freeLen=0;
for(int i=1;i<n;i++)
{
if(A[i]==A[i-1])
{
start=i-freeLen;
freeLen++;
}
else
{
A[start]=A[i];
start=i-freeLen+1;
}
}
return (n-freeLen);
}
};
```