title: How can I find two elements in an array that sum to k
body: <p>Suppose you are given an array of unsorted integers as</p>
  
  <pre><code>A = {3,4,5,1,4,2}
  </code></pre>
  
  <p>Input : <code>6</code> 
  Output : <code>{5,1}, {4,2}</code></p>
  
  <p>How can I do this in O(n) or O(log n). Any suggestions will be appreciated.</p>
  
  <p><strong>Update:</strong>
  Can we write something more efficient than this?</p>
  
  <pre><code>for(int i=0;i&lt;array.length-1;i++)  
  {  
      if(array[i]+array[i+1]==6)  
          System.out.println("{"+array[i]+","+array[i+1]+"}");  
  }  
  </code></pre>