Skip to content

visual walkthrough

Guess Number Higher or Lower

EasyClassic Binary SearchReported at: AdobeBloomberg

An interactive-API variant that forces careful boundary updates.

Solve on LeetCode

The idea

Every "higher" or "lower" reply rules out everything on one side of the guess.

Guessing the middle makes the worst case as small as possible: half the range disappears every time.

Complexity

approachtimespace
Guess 1, 2, 3, …O(n)O(1)
Guess the middleO(log n)O(1)

More walkthroughs