Codewars: Sum Of Pairs

Problem:
* Given a list of integers and a single sum value, return the first two values (parse from the left please) in order of appearance that add up to form the sum.Source: https://www.codewars.com/kata/sum-of-pairs

At this point, we only optimized for a couple of edge cases. We did not really reduce the complexity of the algorithm in the worst case every item in the array would need to be compared with every item in the array O(n*n). As even when we are using the internal functions we are still iterating over all items.

Next Optimization Round:
* Instead of iterating and forgetting what we did let's save our result.

Initially, I had a solution to map all values to an array and then iterate and find the pairs so it would have been O(2*n). But I had difficulties implementing that solution as the array of values could contain duplicates. Then I thought about it and said, hey if I simply compare the current value with the previous values then If I find a match, then I can stop and it would always be the right value. and as a bonus, the complexity is now 0(n), as if the pair is the last two elements of the array we would have needed to visit all elements before that.

comparing the first and the last solution there is a tradeoff between the two solutions.
1. In the 0(n*n) solution it takes longer to get to the result. However, we do not need so much memory.
2. With the O(n) solution, we get the result quicker, but we need a lot more memory.