In a technical interview, you've have been given an array of numbers and you need to find a pair of numbers which are equal to the given target value. Numbers can be either positive, negative or both. Can you design an algorithm that works in O(n) - linear time or greater?
let sequence = [8, 10, 2, 9, 7, 5] let results = pairValues(11) = //returns (9, 2)
Hints
What’s interesting about this solution is that it can be solved using different techniques. The obvious challenge is knowing which numbers can be paired to achieve the expected result. How could this work, assuming your algorithm is only permitted to scan the sequence once?