time:O(n^2),space:O(n)
time:O(n),space:O(n)