You have two integer arrays, a and b, and an integer target value v. Determine whether there is a pair of numbers, where one number is taken from a and the other from b, that can be added together to get a sum of v. Return true if such a pair exists, otherwise return false.
Example
For a = [1, 2, 3], b = [10, 20, 30, 40], and v = 42, the output is true because 40 + 2 = 42.
The above is my problem. I have the correct solution but I want a better way to write the solution...I want it to run faster. I'm currently using two for loops:
function sumOfTwo(a, b, v) {
for(var i=0; i < a.length; i++) {
for(var j=0; j < b.length; j++) {
if(a[i] + b[j] === v) {
return true;
}
}
}
return false;
}
Any Help is appreciated!