C++ easy solution using 2 pointers


#1
int i=1,j=1;
for(; i<A.size() && j<A.size();i++){
    if(A[i]!=A[j]){
        A[j]=A[i];
    }
    if(A[j-1]!=A[j]){
        j++;
    }
}
return j;

#2

can you explain the logic?
thanks!


#3

A good approach, but in question it is mention to change the entire array. You are only counting the number of different element in given array.