public int removeElement(int[] A, int elem)

{

```
if (A.length ==0)
{
return 0;
}
else
{
int i =0;
int j = A.length-1;
while (i<=j)
{
while(j>=0 && A[j]==elem)
{
j--;
}
if(A[i]==elem && j>=0)
{
A[i]=A[j];
i++;
j--;
}
else
{
i++;
}
}
return j+1;
}
```

}