Complexity O(n^2)