visual walkthrough
Guess Number Higher or Lower
An interactive-API variant that forces careful boundary updates.
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
| approach | time | space |
|---|---|---|
| Guess 1, 2, 3, … | O(n) | O(1) |
| Guess the middle | O(log n) | O(1) |