title: Counting number of distinct integers in array
body: <p>To find the number of distinct numbers in an array from the <code>l</code>th to the <code>r</code>th index, I wrote a code block like:</p>
  
  <pre><code>int a[1000000];
  //statements to input n number of terms from user in a.. along with l and r
  
  int count=r-l+1; //assuming all numbers to be distinct
  for(; l&lt;=r; l++){
      for(int i=l+1; i&lt;=r; i++){
          if(a[l]==a[i]){
              count--;
              break;
          }
      }
  }
  cout&lt;&lt;count&lt;&lt;'\n';
  </code></pre>
  
  <p><strong>Explanation</strong>
  For an array say, a=<code>5 6 1 1 3 2 5 7 1 2</code> of ten elements. If we wish to check the number of distinct numbers between a[1] and a[8] that is the second and the 9th elements (including both), The logic I tried to implement would first take count=8 (no. of elements to be considered) and then it starts from a[1] that is 6 and checks for any other 6 after it, if it does find, it decreases the count by one and goes on for the next number in the row. So that if there are any more occurrence of 6 after that one, it would not be included twice.</p>
  
  <p><strong>Problem</strong> I tried small test cases and it works. But when I tried with bigger data, it did not work, so I wanted to know where would my logic fail?</p>
  
  <p><em>Bigger data, as in integrated with other parts of the program and then used. Which gave incorrect output</em></p>