The following code is doing the task in two passes which is O(n) by adding all the numbers to a dictionary (pass I) and then going over the number one-by-one and looking up the complementary number in the dictionary (pass II):
Try another way