CodeGround
DashboardProblemsInterviewsAssessmentsCourses
CodeGround
DashboardProblemsInterviewsAssessmentsCourses
The Technical Interview Course

0 of 170 lessons complete

  • Finding where a property flips
  • Searching something that is not a list
  • Searching the answer instead of the input
  • Discarding a half without full sortedness
  • Working out which half is trustworthy
  • The bisect module, and search inside a design
  • Searching for a split
  • Retrieval: spotting a hidden binary search

Binary Search

46 / 170

Binary Search/Lesson 8 of 8·About 43 min

Retrieval: spotting a hidden binary search

Two problems rebuilt cold, plus the signal that a problem wants a search over answers.

Key idea

Three signals

A sorted input and a question about position, count, or presence. That is the ordinary boundary search.

The words minimum, maximum, smallest, or largest attached to something that must satisfy a condition, with no sorted array anywhere. That is a search over the answer space, and the work is writing the feasibility test.

A constraint mentioning log time when the input is not sorted. That is a hint that some structure other than sortedness lets you discard a half, and finding that structure is the problem.

Tip

The question that settles it

For any candidate binary search, ask: if I test the middle candidate, does the result tell me which side to keep? If yes, write the loop. If no, the property is not monotone and no amount of fiddling with the bounds will fix it.

Quick check· 5 min

Is this a binary search?

You must find the smallest number of machines needed so that a batch of jobs finishes within a deadline, where more machines never make things slower. Does binary search apply, and over what?

Problem· 18 min

Koko Eating Bananas, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

Problem· 15 min

Min Stack, from scratch

You have solved this one before. Rebuild it from scratch without looking at your old submission. If the approach does not come back within a few minutes, that is the signal that it needs another pass.

PreviousSearching for a split
NextWhen do two intervals conflict?

0 of 4 parts complete