Amazon interview question

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