Look for monotonicity
Values, positions, or possible answers split into two regions: too small / large enough, false / true, infeasible / feasible.
Coding Patterns/04 · Monotonic decisions
Values, positions, or possible answers split into two regions: too small / large enough, false / true, infeasible / feasible.
Before every iteration, the answer—if one exists—must remain inside the active interval. Every boundary move needs a proof.
Use mid ± 1 only after proving mid cannot be the answer. Use right = mid when mid is still a valid candidate.
Runnable session
Five exercises · Python 3 · visible checks · saved locally
Implement find_release(releases, target). releases is a sorted list of unique integer build numbers. Return the index of target, or -1 when it is absent.
Build 121 is at zero-based index 3.
110 falls between two builds but is not present.
Your code runs privately in the browser. Visible checks cover empty, boundary, and representative cases.
The closed interval starts at [0, 6]. Each comparison preserves the invariant and removes a proven-impossible region.
19 is too small. Indices 0 through 3 cannot contain 31.
42 is too large. Indices 5 and 6 cannot contain 31.
The final remaining candidate matches the target.
A linear scan could need five; the gap grows rapidly with input size.