Please Note that :- Here the internal code will traverse from the start of the array to the length Your Return


#1

In this question the length which you return, the internal code will traverse up to that length so you don’t have to explicitly remove the element from the vector.

For Better Understanding see My code.

int Solution::removeDuplicates(vector<int> &nums) {
    // 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
    if(nums.size()==0)
    return 0;
    
    int prev=0;
    for(int i=1;i<nums.size();i++)
    {
        if(nums[prev]==nums[i])
        {
            continue;
        }
        else
        {
            // not same so aage badle chaka maro;
            prev++;
            nums[prev]=nums[i];
        }
    }
    
    
    return prev+1;
    
}

TLE at submission ! please someone point out the mistake