Searching sorted data interview questions
Binary search on sorted lists, on rotated lists and grids, and on the answer itself, with the loop invariants that prevent off-by-one bugs.
– interview-ready · 12 questions in this topic
– of 12 tried
Saved on this device. Interview-ready means you got it right on two different days. Guesses and hints count for less.
Questions
- Where would a new price go in a sorted list?Predict
- Slowest reading pace that still finishes on timePredict
- Smallest value in a rotated sorted listPick the fix
- Find a value in a rotated sorted listPredict
- First and last position of a value in a sorted listFill the blank
- Whole-number square root without math.sqrtPredict
- Smallest truck that delivers every parcel in d daysPredict
- Highest point of a climb-then-descent routePick the fix
Practise this topic
Flashcards · 22
Flip, then say if you knew it. Needs JavaScript; every answer is also on its question page.
Quick quiz · 12 questions
One exercise per question, checked as you go. Needs JavaScript.
Mock interview · 2 sets
Timed, out loud, then tick what you covered. Needs JavaScript.
Quick facts
Recall the answer first, then tap Show to check.
bisect.bisect_leftbisect_left(a, x)returns the first index where x could be inserted to keepasorted: the first position witha[i] >= x.bisect.bisect_rightbisect_right(a, x)returns the position after any existing copies of x: the first position witha[i] > x.bisectkey argumentSince Python 3.10,
bisectfunctions acceptkey=, so you can search a list of records by one field.math.isqrtmath.isqrt(n)returns the floor of the square root of a non-negative integer exactly, with no floating-point rounding.Kotlin
binarySearchList.binarySearch(x)returns the index if found, otherwise-(insertion point) - 1.
Printable cheat sheet · Review your weak spots in this topic
Share your progress
Sources: Topic outline informed by the Tech Interview Handbook by Yangshun Tay and the NeetCode 150 pattern grouping by neetcode-gh, both MIT licensed. Every problem, solution and explanation is written by Best Latest Apps. Credits and license