Very very troubling test case InterviewBit ;-; (read till end)


#1
int Solution::removeDuplicates(vector<int> &A) {
    int i = 0, j = 1, N = A.size();
    if(N == 1) return A[0];
    A.push_back(A[0]);
    
    while(i < N-1 && j < N){
        if(A[j] == A[i]){
            //A.push_back(A[i]);
            j++;
        }
        else {
            A.push_back(A[j]);
            i = j;
            j+=1;
        }
    }
    A.erase(A.begin(), A.begin()+N);
    return A.size();

   
}

Hey guys! Do run this code and check. Take any custom test case and run it first. It will work BEAUTIFULLY. Now run the testcase of IB. It will say wrong and and give this test case : [ 0 ].
Now, that the heck is this test case?! What are those spaces around 0? I’m so pissed off right now :face_with_head_bandage:
If anyone can figure out why I’m wrong, I’ll be in your debt. Thanks


#2

because you have put initial condition wrong
If(N==1) return 1;


#3

Yep, that was it! Thank you! :slight_smile: