Amazon interview question

4 Sum question, brute force to optimization.