Skip to main content

Checkpoint: The Missing Boundary

Challenge on lesson: Checkpoint — The Lost Boundary

CHALLENGE
Difficulty: advanced+25 XP

**Task.** A sorted array of n distinct values; one query value x. Print the smallest index i (0-indexed) with a[i] >= x, or −1 if none. **The code under test** (fix it mentally, then submit the CORRECT version): the shipped binary search tests a[mid] <= x and records the answer only in the else branch. Trace what happens when x EQUALS a qualifying element (e.g., x is the last element of the array). **Constraints:** 1 ≤ n ≤ 200000; 0 ≤ a_i, x < 10^9.

Back to lesson: Checkpoint — The Lost Boundary