Add the O(1) space solution