time O(n) space O(n)  one travel