Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Troubleshooting a Problem with Removing Duplicates from an Array

Titan_STitan_S Member
edited April 2023 in Programming

I'm having trouble trying to remove duplicates from an array using the code found on this resource.

I'm using the following code:

int removeDuplicates(int A[], int n)


 if (n==0 || n==1)

  return n;


 int j = 0;


 for (int i=0; i < n-1; i++)

  if (A[i] != A[i+1])

   A[j++] = A[i];


 A[j++] = A[n-1];


 return j;


When I run the code, the result is that the duplicates are not being removed. I would really appreciate any help in troubleshooting this issue.


Sign In or Register to comment.