left
and right
, to represent the range of possible values for n
. Set left
to 1 and right
to a large number (e.g., 1000000) to ensure it covers the possible range.mid
as the average of left
and right
.
b. Compute the total number of apples using the formula with mid
as n
.
c. If the total number of apples is greater than or equal to neededApples
, update right
to mid
.
d. Otherwise, update left
to mid + 1
.left
is equal to right
.8 * left
.