Time complexity: O(n log(n))
Space complexity: O(n)
Runtime 6 ms Beats 98.28% Memory 44.37 MB Beats 88.61%