Time complexity: O(n log(n))
Space complexity: O(n)
Runtime 9 ms Beats 97.21% Memory 45.58 MB Beats 87.01%