Modified Binary Search Cheat Sheet

Narrow a sorted range in half each step instead of scanning it, keeping lo and hi until they cross to land on the left-most or right-most match.

Modified Binary Search cheat sheet preview

Earn the full sheet below.

When to reach for it

  • The list is sorted (or reframed as a sorted range of answers) and a plain scan is too slow.
  • You need the left-most or right-most position of a target, not just any match.
  • The question asks for O(log n) on a list, or checks a validator across a range.
  • The list is 'almost sorted' (rotated), but binary search still works once you find the clean half.

What's on the sheet

The halving is identical every time. Step 3 decides what found means.

  1. Variable Initialization. lo and hi bracket the range; result holds the hit.
  2. Binary Search Initialization. The loop and mid never change shape.
  3. Validation. On a match: record it, keep hunting one side.
  4. Search. Always skip past mid. Reusing it as a bound loops forever.

Watch out

  • The loop condition is lo <= hi, not <; dropping the equals skips the last remaining candidate.
  • Finding the target is not the finish line for left/right-most questions (First and Last Positions in a Sorted List). Keep narrowing instead of breaking.

How to earn it

Solve half of the Modified Binary Search problems on InterviewCrunch and the sheet is yours. Free accounts included. Members can download every sheet right away.

Want to see a finished sheet first? Preview the Two Pointers sample.

Every pattern has a sheet. See the full set.