Time complexity: O(n)
Space complexity: O(1)
Space complexity: O(n)
Time complexity: O(n log(n))
Space complexity: O(log(n))