Time: (O(n)), Space: O(1)
Time: O(m+n), Space: O(m+n)