How it works
Core loop
Track low and high bounds, compute a mid index, and move the bound that cannot contain the target.
Search on the answer
Many problems binary search over a range of possible answers, not just array indices.
Common pitfalls
Guard against overflow in mid calculation and off-by-one errors in loop bounds and termination.