Amazon Interview Question

How would you optimize the implementation that you provided from O(n2)?