⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 27s17 days 22 hours 20 minutes 27 seconds.
⚡ Build the skills to land top-paying quant jobs. Offer ends in 17d 22h 20m 27s17 days 22 hours 20 minutes 27 seconds.

Sign in to watch this lesson
Algorithms - Sorting and Searching · 6:13
We build binary search around one invariant: l always sits on a 'no', r on a 'yes', with ghost sentinels at -1 and n, and the loop runs while r - l > 1. Tracing lower_bound(9) and upper_bound(9) on [1, 3, 5, 7, 9, 9, 13, 15] gives 4 and 6, the half-open range of the two 9s. Then the classic traps (a closed-interval l = m loop that never ends and an (l + r) / 2 that overflows), partition_point and jump search, and measurements on this Mac, including why std::lower_bound on a std::set is tens of thousands of times slower than s.lower_bound.