For two-sum, you're looking for pairs where . So . For each element :
Check if is in the hash map
If yes, you found a pair
Add to the hash map The hash map stores elements you've seen. For each new element, you check if its "complement" was seen before.