Loading page…
A bank app keeps its last million flagged transactions in a ring buffer that has wrapped, so the ids read as a sorted list that starts in the middle. Scanning it for thirty thousand look-ups costs thirty billion comparisons. The ring is two sorted runs: a first-true search on the last id finds the break, and a lower bound inside the right run finds the id. The lesson adds a peak search that walks toward the higher neighbour, and tells the truth about repeats: the worst case is linear.
You work on the fraud checks of a bank app.