O(1) space, AC