v12 time O(n^2log(n)) space O(n) Accepted