Problem. Given a sorted array of distinct integers and a target, return the index of target if it's
there; otherwise return the index where it would be inserted to keep the array sorted. Must run in O(log n).
nums = [1, 3, 5, 6], target = 5 → 2
nums = [1, 3, 5, 6], target = 2 → 1
nums = [1, 3, 5, 6], target = 7 → 4
Both cases have one answer: the first index whose value is ≥ target. That's the boundary search from lesson 5.1.
ML context. "Where would this value go?" is how features are bucketized: an age, a price or a score is mapped
to a bin by searching sorted bin edges (np.digitize, torch.bucketize, quantile binning for gradient-boosted trees).
It's also how you find the nearest timestamp in a log, or the step closest to a given wall-clock time.