title: First common number in both arrays of size 1 million
body: <p>I have two very large arrays of integer, each one is of size approximately 1 million. I have to find first integer which is present in both arrays.</p>
  
  <p>I tried to do this using a set. </p>
  
  <p>(1) Traverse each array simulatneously and insert elements of both array in set.</p>
  
  <p>(2) Whenever set refuses to accept that is the first intersection.</p>
  
  <pre><code>int Solution(int A[], int B[])
  {
      Set s = new HashSet();
      for (int i = 0 ; ; i++)
      {
          if ( i &lt; A.length )
          {
              if( !s.Add(A[i]) )
                  System.out.println(A[i]);
          }
          if ( i &lt; B.length )
          {
              if( !s.Add(B[i]) )
                  System.out.println(B[i]);
          }
      }
  }
  </code></pre>
  
  <p>Can we improve this solution to reduce time complexity ?</p>
  
  <p>Thanks</p>