Basically, the code binary search the optimal time. One thing I can't understand is its stop condition (and then the choice of the optimal answer). The while stop condition in the main function is
ma - mi > 1, i.e., it will stop when
mi + 1 = ma and (I think) there will never be such case that
mi = ma. After that while, he prints the value of
ma (right 'pointer' of binary search).
My doubt is: why can't
mi be the optimal answer? How is he sure that
ma is already the optimal answer despite the fact that
mi is still inside the 'search' range?
Any help is appreciated. Thanks!