0

In these arrays, the numbers can be either positive or negative. Only one number from each array may be used.

I received this question as an algorithms question on a phone interview and it stumped me. The interviewer seemed to believe there was an O(n) solution.

Edit: My question is different than the "possible duplicates" because this question involves 2 arrays, rather than one.

C. Parks
  • 63
  • 5
  • Possible duplicate of [Find a pair of elements from an array whose sum equals a given number](http://stackoverflow.com/questions/4720271/find-a-pair-of-elements-from-an-array-whose-sum-equals-a-given-number) – shole Apr 20 '17 at 05:07

1 Answers1

6

For unsorted arrays - fill hash table with the first array values and walk through the second one, checking if Sum-B[i] exists in the table

MBo
  • 72,080
  • 5
  • 47
  • 77