title: Using XOR operator for finding duplicate elements in a array fails in many cases
body: <p>I came across a post <a href="https://stackoverflow.com/questions/2605766/how-to-find-a-duplicate-element-in-an-array-of-shuffled-consecutive-integers">How to find a duplicate element in an array of shuffled consecutive integers?</a> but later realized that this fails for many input.</p>
  
  <p>For ex:<br>
  <code>arr[] = {601,602,603,604,605,605,606,607}</code></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  int main()
  {
  int arr[] = {2,3,4,5,5,7};
  int i, dupe = 0;
  for (i = 0; i &lt; 6; i++) {
      dupe = dupe ^ a[i] ^ i;
  }
  printf ("%d\n", dupe);
  return 0;
  }
  </code></pre>
  
  <p>How can I modify this code so that the duplicate element can be found for all the cases ?</p>