When to Use

Pattern triggers

Look for these signals in the problem:

  • "Sorted array" explicitly mentioned: Classic binary search directly applies. Even if not finding exact values, sorted order enables halving.
  • "Find minimum/maximum that satisfies condition": Binary search on the answer space.

If you can verify a candidate answer in O(n)O(n), search the range in O(logn)O(\log n).

  • "Rotated sorted array": Modified binary search handles the rotation by checking which half is properly sorted.
  • "Find boundary" or "first/last occurrence": Binary search variants find transition points between valid and invalid regions.