Amazon Interview Question

4 Sum question, brute force to optimization.