Search Insert Position
Binary search · Search for the first valid position · Easy · about 18 min
Why it matters
Boundary search is the foundation for harder “search the answer” problems.
How it connects
Binary search is not only exact matching: it can find the boundary where a rule becomes true.
Try first
At the end of a failed search, what does left point to?
Interview cue
I preserve the insertion invariant, so the final left boundary is the answer.