InterviewLegend

Binary Search

Alex Chen20 min readGuide updated 557 real interview reports

At Google, binary search often hides inside another problem, such as a grid path or a scheduling question, as the step that searches for the best value. You write it in a Google Doc that never runs, so every boundary move has to be right on paper.

For two-pointer and sliding-window problems, including how to narrate a sweep's invariant, see Two Pointers & Sliding Window.

Most people learn binary search as finding a value in a sorted array. Google asks a different version more often, binary search on the answer, and fewer people practice it. Here you build the sorted line yourself. The candidate answers form a number line where small answers fail and larger ones pass, and you search that line for the point where failing turns into working.

You can spot it from the wording. When a question asks for the slowest speed or the smallest capacity that still gets the job done, it's the same template pointed at a different scenario. The constraint turns into a yes or no helper, "can we do it with this setting?", that you call inside the search.

Binary search needs one property, monotonicity. As the candidate grows, a feasible(x) check has to read No, No, No, then Yes, Yes, Yes, with a single boundary between them. Then you can binary-search for the first Yes. The classic sorted-array search is the special case where the array is already that line.

GooglePremium lesson · Coding round

The 3 Google problems are below.

  1. A Premium questionCoding · Medium · Frequently asked
  2. A Premium questionCoding · Hard
  3. A Premium questionCoding · Medium

Each with hints, the follow-up and a tested solution.

Get the Google questions

$49 a year · all 122 companies · instant access

557 Google interview reports · guide updated

Google interview guide

Know what Google asks before you walk in.

34 coding · 8 system design · 33 behavioral questions

Get Premium$49 a year · Instant access
Or start freeNo card.

Get their questions first.

Had your Google interview?How we research

InterviewLegend is independent and not affiliated with or endorsed by any company it covers.