time:O(n),space:O(n)
time:O(nlogn),space:O(1)
time:O(n),space:O(1)
time:O(n),space:O(1)