title: Remove duplicates from array C++
body: <p>Input: <code>int arr[] = {10, 20, 20, 30, 40, 40, 40, 50, 50}</code></p>
  <p>Output: <code>10, 30</code></p>
  <p>My code:</p>
  <pre><code>int removeDup(int arr[], int n)
  {
      int temp;
      bool dupFound = false;
  
      for(int i=0;i&lt;n;i++){
          for(int j=i+1;j&lt;n;j++){
              if(arr[i] == arr[j]){
                  if(!dupFound){
                      temp = arr[i];
                      dupFound = true;
                  }
                  else{
                      arr[i] = temp;
                  }
              }
          }
      }
      //shift here
  }
  </code></pre>
  <p>First of all, I don't know if this is the most efficient way of doing this.</p>
  <p>I'm trying to find the first duplicate element, assign it to every duplicate element and shift them to the end of the array, which doesn't work because the last duplicate element cannot be compared.</p>
  <p>I need some help with finding the last duplicate element, so I can assign <code>temp</code> to it.</p>