Hash Table Based Pair Sum Finder

  • Share this:

Code introduction


The function uses a hash table to keep track of the numbers seen so far. It looks for another number in the list that, when added to the current number, equals the target. If found, it returns a list containing both numbers; otherwise, it returns None.


Technology Stack : Built-in data structure (hash table)

Code Type : Algorithm implementation

Code Difficulty : Intermediate


                
                    
def sum_pairs(numbers, target):
    seen = {}
    for num in numbers:
        diff = target - num
        if diff in seen:
            return [diff, num]
        seen[num] = True
    return None