Remove more than 2 duplicates from sorted array

CODE:
int removeDuplicates(vector& nums)
{
int i=0,j=1;
if(nums.size()==1)
return 1;
else if(nums.size()==0)
return 0;
while(j<nums.size())
{
if(nums[i] != nums[j])
{
i=i+2;
nums[i]=nums[j];
}
else if(nums[i] == nums[j])
j++;
}
return nums.size();
}

Input
[0,0,1,1,1,2,3,3]

Output
[0,0,1,1,2,2,3,3]

Expected
[0,0,1,1,2,3,3]

HELP!

Hey @yogeshcsc20
Your logic is little bit incorrect
Here I updated your code :slight_smile:https://ide.codingblocks.com/s/345653

Sir, the question is to remove duplicates if it’s occurrence is more than two times.Ex-00111233 will be converted to 0011233

Please share the link of the question

Hey @yogeshcsc20
Here updated your code: https://ide.codingblocks.com/s/345949
Logic similar to :https://www.youtube.com/watch?v=-jHoA0e-IJ0

Thanks sir. It helped alot.

1 Like