title: optimising for index of pair in an array whose sum is given
body: <p>I am coding for finding all the indexes of pair of numbers in an array whose sum is already given.</p>
  
  <pre><code>for(i=0;i&lt;max;i++)
  {
      for(j=i+1;j&lt;max;j++)
      {
          if(a[i]+a[j]==sum)
              printf("%d %d\n",i,j);
      }
  }
  </code></pre>
  
  <p>where max is maximum size of array. And sum is the sum of pair of numbers.(There could be repetition of values in the array.)</p>
  
  <p>But I get only this naive O(n^2) solution. Can anyone help me out in getting best solution possible for this case.</p>