3 ms·
Find two numbers from an array that sum to a target number
- Someone 8y ago”The time complexity is O(n) because we iterate the array of numbers containing n elements only once.” If only. That ignores the dictionary look ups. Also, there’s the tiny problem that this code is buggy. It only works if, for every number in the array, target - number also is in the array. It doesn’t even work for the example given in the problem description, returning (9,0) as one of the answers. I hope this was posted as a warning that not everything you google is correct since, otherwise, this would not be interesting at all.