use only constant extra space