o(n) extra space O(n)