leftover: O(1) space complexity