Given a sum, find two numbers in an array with that sum.
Interview Answers
Anonymous
17 June 2015
Using JS:
nums = [2,13,61,512,3,6,7,88,17]
sum = 15
for(var i = 0; i -1) {
return nums[match];
}
}
Anonymous
3 Aug 2015
The other answer works, but is not efficient (It is O(n^2))
To make it O(n), simply make a hashmap. For every number, check to see if the number exists in the hashmap, otherwise store [sum-currentNumber]