title: Find all combinations of records which sums to zero in three array lists?
body: <p>Consider there are three array list each of equal length and having positive, negative and zero in them. I had to write a program to find combinations of which sum comes to zero. So basically, if the arrays were:-</p>
  
  <pre><code>A = {0, -1, 2}
  B = {0, -1, -2}
  C = {0, -2, 0}
  </code></pre>
  
  <p>O/P: A[0] + B[0] + C[0], A[2] + B[2] + C[2] etc.</p>
  
  <p>I could think of two ways,
  1. Have 3 for loops and calculate the sum using a[i] + b[j] + c[k], if zero print the index. 
     Big O will be O(N^3)
  2. Have two for loop but use Binary Search to find the third element which would give the sum as zero. 
     Big O will be O(N^2LogN)</p>
  
  <p>Any other ways?</p>
  
  <p>Thanks.</p>
  
  <p><strong>EDIT:</strong>
  Based on the answers given below, my first soln is the fastest possible. But if the question is about "finding" the number of combinations and <strong>NOT</strong> printing them, then please see Grigor Gevorgyan answer below.</p>