Same O(n^2) complexity problem here.