Time: O(*), Space: O(*)