Sobes.tech
Junior — Senior

Finding a pair of array elements that sum to a given value

livecode

Task condition

Given a set of numbers. Write a function that checks whether there are two elements in this set whose sum equals a given value. The solution should work in O(n) time and O(n) space.

 const hasPairWithSum = (numbers, target) => {}

hasPairWithSum([3, 4, 7, 10], 8); // false
hasPairWithSum([1, 4, 4, 9], 8); // true
hasPairWithSum([-8, 1, 4, 9, 16], 8); // true