AlgorithmsIntermediate
Binary Search Without Off-by-One Bugs
Binary search is easy to explain and surprisingly easy to get wrong. Learn one loop invariant that makes it correct every time, find first and last positions, and use binary search on answers instead of arrays.