title: Remove duplicates from an unsorted array
body: <p>I'm trying to create a function to remove duplicates from an unsorted int array. I have a solution that works for more examples, but it's failing with the following input:</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int removeDuplicates(int arr[], int n)
  {
      int j = 0;
  
      for (int i=0; i &lt; n; i++){
          for(int j=0;j&lt;=i;j++){
  
              if(arr[i]==arr[j]){
                   n--;
                  for (int k=i; k&lt;n; k++){
                      arr[k]=arr[k+1];
                  }
              }
          }
      }
  
      return n;
  }
  
  // Driver code
  int main()
  {
      int arr[] = {0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1};
      int n = sizeof(arr) / sizeof(arr[0]);
  
      n = removeDuplicates(arr, n);
  
      for (int i=0; i&lt;n; i++)
          cout &lt;&lt; arr[i] &lt;&lt; " ";
  
      return 0;
  }
  </code></pre>
  
  <p>The output for this arr example is 0 0 1 0 0 and should be 0 1.</p>
  
  <p>Do you see where is the problem? Thank you</p>