memoized remainingApples to improve performance