left
and right
to 1 and n
respectively.left
is less than or equal to right
:
a. Calculate the middle of the current range as mid = left + (right - left) / 2
.
b. Make a guess using mid
and store the result of guess(mid)
.
c. If the result is 0, return mid
as the picked number.
d. If the result is -1, adjust the right
pointer to mid - 1
.
e. If the result is 1, adjust the left
pointer to mid + 1
.