Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Checkpoint โ€” The Lost Boundary

โญโญโญ advancedโณ 25 min read๐Ÿ“ Lesson 239 of 281

Lower-bound binary search: the shipped code loses the answer when it is the last index (closed-interval + early hi shrink). Fix it; the tests pin the boundary and the all-tie case.

Checkpoint โ€” The Lost Boundary. The provided binary search looks canonical but answers the wrong predicate: a[mid] <= x makes it return the first index strictly GREATER than x (upper_bound), so when x equals qualifying elements โ€” the last-element boundary, or an all-equal array โ€” it reports โˆ’1. The repair is one character: < instead of <=, with the post-loop existence check intact. The boundary and all-tie tests are exactly the shapes the stumble cannot survive.