Roadmap › Stage 3: Binary Search › Pattern 13 of 53
DSA pattern guide

Binary Search — Classic

Sorted (or rotated sorted) input, find a target or a boundary, O(log n) required.

Stage 3 · Binary Search9 problems3 Easy · 6 Medium

Use it when

Sorted (or rotated sorted) input, find a target or a boundary, O(log n) required.

Key idea

Keep an invariant on [lo, hi] and halve it each step. Decide which half is sorted when rotated.

Practice problems, in order

  1. Binary SearchEasy
  2. Sqrt(x)Easy
  3. Search Insert PositionEasy
  4. Search in Rotated Sorted ArrayMedium
  5. Find Minimum in Rotated Sorted ArrayMedium
  6. Find Peak ElementMedium
  7. Find First and Last Position of ElementMedium
  8. Search a 2D MatrixMedium
  9. Search a 2D Matrix IIMedium

How to practise this pattern

  1. Read the problem and look for the signal above before writing any code.
  2. Say the brute force out loud, with its time complexity, then ask what work it repeats.
  3. Apply the key idea and write the optimised version yourself.
  4. If you're stuck for more than 10 minutes, take one small hint, not the full solution.
  5. Move to the next problem only when you can explain why this pattern fits.

Stuck on one of these?

The AlgoSolveo extension (free, launching soon) sits beside the LeetCode problem and gives the smallest hint that gets you moving, never the full answer. Solved problems tick off on your roadmap.

Join the extension waitlistTrack it on the roadmap
← Previous patternHashMap — Frequency & PrefixNext pattern →Binary Search on Answers