This gives time limit exceeded. Please help


#1

int j=0,count=0;
int n=A.size();

for(int i=0;i<n;i++){

    
    if(A[j]==B){
        
        A.erase(A.begin()+j);
        count++;
    }
    else{
        j++;
        
    }
}
return n-count;

#2

int Solution::removeElement(vector &A, int B) {
// 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

int n=A.size();
int j=0;

for(int i=0;i<n;i++)
{
    if(A[i]!=B)
    A[j++]=A[i];
}

return j;

}
use this


#3

@kirti-palve
Bro, it has O(n*n) time complexity. As erase function has O(n) time complexity itself so it is giving tle.