```
class Solution {
public:
int removeElement(int A[], int n, int elem) {
int index = 0;
int tail = n - 1;
while(index <= tail){
if(A[index] == elem){
A[index] = A[tail];
tail -= 1;
}else{
index++;
}
}
return tail + 1;
}
};
```