To ace your coding interview for a software engineering job, you’ll need to understand binary search. It comes up frequently in coding interviews and is fundamental to many other algorithms too.
Let’s take a look at some typical binary search questions.
6 typical binary search interview questions

Given an array of integers nums that is sorted in ascending order, and an integer target, write a function to search target in nums. If target exists, then return its index. Otherwise, return 1.

Given the sorted rotated array nums of unique elements, return the minimum element of this array in O(log n) time.

Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:
Integers in each row are sorted from left to right.
The first integer of each row is greater than the last integer of the previous row. 
Given a sorted array of distinct integers and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order with O(log n) runtime complexity.

Given the array nums after the possible rotation and an integer target, return the index of target if it is in nums, or 1 if it is not in nums.

Given two sorted arrays nums1 and nums2 of size m and n respectively, return the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).
Below, we take a look at 50 binary search questions and provide you with links to high quality solutions to them.
This is an overview of what we’ll cover:

Easy binary search interview questions
 Medium binary search interview questions
 Hard binary search interview questions
 How to prepare for a coding interview
Let's get started.
1. Easy binary search interview questions
You might be tempted to try to read all of the possible questions and memorize the solutions, but this is not feasible. Interviewers will always try to find new questions, or ones that are not available online. Instead, you should use these questions to practice the fundamental concepts of binary search.
As you consider each question, try to replicate the conditions you’ll encounter in your interview. Begin by writing your own solution without external resources in a fixed amount of time.
If you get stuck, go ahead and look at the solution, but then try the next one alone again. Don’t get stuck in a loop of reading as many solutions as possible! We’ve analysed dozens of questions and selected ones that are commonly asked and have clear and high quality answers.
Here are some of the easiest questions you might get asked in a coding interview. These questions are often asked during the “phone screen” stage, so you should be comfortable answering them without being able to write code or use a whiteboard.
Question 1: Search insert position
 Text guide (GeeksForGeeks)
 Video guide (NeetCode)
 Video guide (TECH DOSE)
Question 2: Sqrt(x)
 Text guide (GoodTecher)
 Video guide (Terrible Whiteboard)
 Code example (AlexTheGreat)
Question 3: First bad version
 Text guide (Medium/Mac Sampson)
 Video guide (Kevin Naughton Jr.)
 Code example (Cheng_Zhang)
Question 4: Intersection of two arrays
 Text guide (AfterAcademy)
 Code example (divingboy89)
Question 5: Valid perfect square
 Text guide (Dev.to/Aroup)
 Video guide (TECH DOSE)
 Code example (LeetCode)
Question 6: Guess number higher or lower
 Text guide (Dev.to/Mridu Bhatnagar)
 Video guide (Coding Decoded)
 Code example (StefanPochmann)
Question 7: Arranging coins
 Text guide (just4once)
 Video guide (Naresh Gupta)
 Code example (ratchapongt)
Question 8: Binary search
 Text guide (AminiCK)
 Video guide (Nick White)
 Code example (LeetCode)
Question 9: Find smallest letter greater than target
 Text guide (Callicoder)
 Video guide (Eric Programming)
 Code example (nrl)
Question 10: Peak index in a mountain array
 Text guide (Memogrocery)
 Video guide (Nick White)
 Code example (lee215)
Question 11: Count negative numbers in a sorted matrix
 Text guide (TechieDelight)
 Video guide (Sai Anish Malla)
 Code example (gthor10)
Question 12: Find the distance value between two arrays
 Text guide (TutorialCup)
 Video guide (onepunchcoder)
 Code example (LeetCode)
Question 13: Kth missing positive number
 Text guide (TutorialCup)
 Text guide (The Startup)
 Video guide (Algorithms Made Easy)
 Code example (lee215)
2. Medium binary search interview questions
Here are some moderatelevel questions that are often asked in a video call or onsite interview. You should be prepared to write code or sketch out the solutions on a whiteboard if asked.
Question 14: Search in a rotated sorted array
 Text guide (Educative)
 Video guide (NeetCode)
 Video guide (Errichto)
 Code example (1337beef)
Question 15: Find first and last position of element in sorted array
 Text guide (Enjoy Algorithms)
 Video guide (Nick White)
 Code example (stellari)
Question 16: Search a 2D matrix
 Text guide (TheLeanProgrammer)
 Video guide (NeetCode)
 Code example (LeetCode)
Question 17: Search in rotated sorted array II
 Text guide (Programcreek)
 Video guide (Knowledge Center)
 Code example (LeJas)
Question 18: Find minimum in rotated sorted array
 Text guide (Callicoder)
 Video guide (Nick White)
 Video guide (NeetCode)
 Code example (water1111)
Question 19: Find peak element
 Text guide (Techie Delight)
 Video guide (Kevin Naughton Jr.)
 Video guide (Errichto)
 Code example (gangan)
Question 20: Count complete tree nodes
 Text guide (Medium/AlgoMonster)
 Video guide (TECH DOSE)
 Code example (StefanPochmann)
Question 21: Search a 2D matrix II
 Text guide (Dev.to/seanpgallivan)
 Video guide (Algorithms Made Easy)
 Code example (chicm)
Question 22: Longest increasing subsequence
 Text guide (Algorithmsandme)
 Video guide (take U forward)
 Code example (dietpepsi)
Question 23: Hindex II
 Text guide (Evelynn)
 Video guide (TECH DOSE)
 Code example (LeJas)
Question 24: Random pick with weight
 Text guide (Massive Algorithms)
 Video guide (TECH DOSE)
 Code example (LATTES)
Question 25: Heaters
 Text guide (just4once)
 Video guide (happygirlzt)
 Code example (shawngao)
Question 26: Kth smallest element in a sorted matrix
 Text guide (Medium/Ayoub Omari)
 Video guide (Winson Ye)
 Code example (YuanGao)
Question 27: Single element in a sorted array
 Text guide (Web Rewrite)
 Video guide (TECH DOSE)
 Code example (baguette)
Question 28: Find K closest elements
 Text guide (Zirui)
 Video guide (Ren Zhang)
 Code example (lee215)
Question 29: Koko eating bananas
 Text guide (Dev.to/codingpineapple)
 Video guide (Michael Muinos)
 Code example (GraceMeng)
Question 30: Online election
 Text guide (Massive Algorithms)
 Video guide (Cat Racket Code)
 Code example (lee215)
Question 31: Time based keyvalue store
 Text guide (Linlaw Techblog)
 Video guide (Michael Muinos)
 Code example (votrubac)
Question 32: Capacity to ship packages within D days
 Text guide (GeeksForGeeks)
 Video guide (code Explainer)
 Code example (lee215)
3. Hard binary search interview questions
Similar to the medium section, these more difficult questions may be asked in an onsite or video call interview. You will likely be given more time if you are expected to create a full solution.
Question 33: Median of two sorted arrays
 Text guide (Medium/hamid)
 Video guide (NeetCode)
 Code example (MissMary)
Question 34: Count of smaller numbers after self
 Text guide (Seanforfun)
 Video guide (happygirlzt)
 Code example (mayanist)
Question 35: Find minimum in rotated sorted array II
 Text guide (GraceMeng)
 Video guide (Naresh Gupta)
Question 36: Russian doll envelopes
 Text guide (Dev.to/seanpgallivan)
 Video guide (Algorithms Made Easy)
 Code example (TianhaoSong)
Question 37: Max sum of rectangle no larger than K
 Text guide (just4once)
 Video guide (Happy Coding)
 Code example (javachao)
Question 38: Split array largest sum
 Text guide (Nitish Chandra)
 Video guide (happygirlzt)
 Code example (dax1ng)
Question 39: Smallest good base
 Text guide (just4once)
 Code example (wgl)
Question 40: Reverse pairs
 Text guide (fun4LeetCode)
 Video guide (take U forward)
 Code example (Tutorialspoint)
Question 41: Kth smallest number in multiplication table
 Text guide (seanforfun)
 Text guide (LeetCode)
 Video guide (Coders Camp)
 Code example (shawngao)
Question 42: Random pick with blacklist
 Text guide (Massive Algorithms)
 Video guide (babybear4812)
 Code example (wangzi6147)
Question 43: Find Kth smallest pair distance
 Text guide (Medium/Timothy Huang)
 Video guide (code Explainer)
 Code example (fun4LeetCode)
Question 44: Kth smallest prime fraction
 Text guide (seanforfun)
 Video guide (Happy Coding)
 Code example (fun4LeetCode)
Question 45: Preimage size of factorial zeroes function
 Text guide (fun4LeetCode)
 Text guide (just4once)
 Code example (walkccc)
Question 46: Nth magical number
 Text guide (just4once)
 Video guide (Shivam Patel)
 Code example (lee215)
Question 47: Longest duplicate substring
 Text guide (Medium/Anshika Bhargava)
 Video guide (TECH DOSE)
 Code example (lee215)
Question 48: Maximum profit in job scheduling
 Text guide (Tutorials point)
 Video guide (Timothy H Chang)
 Code example (lee215)
Question 49: Find in mountain array
 Text guide (lee215)
 Video guide (babybear4812)
 Code example (Medium/Yinfang)
Question 50: Online majority element in subarray
 Text guide (Massive Algorithms)
 Code example (lee215)
4. How to prepare for a coding interview
4.1 Refresh your knowledge
Before you start practicing interviews, you’ll want to make sure you have a strong understanding of not only binary search but also the rest of the relevant algorithms and data structures. Check out our guides for detailed explanations and useful cheat sheets.
Algorithms explained:
 Depthfirst search
 Breadthfirst search
 Binary search
 Sorting
 Dynamic programming
 Greedy algorithm
 Backtracking
 Divide and conquer
Data structure guides:
4.2 Practice on your own
Once you’re confident in all of these, you’ll want to start working through lots of coding problems.
For binary search you can obviously use the questions we’ve listed above. For the other algorithms you need to know, check out the rest of this series:
 Depthfirst search interview questions
 Breadthfirst search interview questions
 Sorting interview questions
 Dynamic programming interview questions
 Greedy algorithm interview questions
 Backtracking interview questions
 Divide and conquer interview questions
We also recommend working through our list of 73 data structure interview questions.
One of the main challenges of coding interviews is that you have to communicate what you are doing as you are doing it. Talking through your solution out loud is therefore very helpful. This may sound strange to do on your own, but it will significantly improve the way you communicate your answers during an interview.
It's also a good idea to work on a piece of paper or google doc, given that in the real interview you'll have to code on a whiteboard or virtual equivalent.
3.3 Practice with others
Of course, if you can practice with someone else playing the role of the interviewer, that's really helpful. But sooner or later you’re probably going to want some expert interventions and feedback to really improve your coding interview skills.
That’s why we recommend practicing with exinterviewers from top tech companies. If you know a software engineer who has experience running interviews at a big tech company, then that's fantastic. But for most of us, it's tough to find the right connections to make this happen. And it might also be difficult to practice multiple hours with that person unless you know them really well.
Here's the good news. We've already made the connections for you. We’ve created a coaching service where you can practice 1on1 with exinterviewers from leading tech companies. Learn more and start scheduling sessions today.
Any questions about binary search interview questions?
If you have any questions about binary search or coding interviews in general, don't hesitate to ask them in the comments below. All questions are good questions, so go ahead!