Time: O(n^2Logn), Space: O(n^2)