Binary Search Problems for Coding Interviews
Binary search is not only for sorted arrays: it works whenever you can test a yes or no condition that flips exactly once. That includes searching an answer range (minimum capacity, smallest speed) as well as finding a position.
Most bugs come from off-by-one boundaries. Fix a convention (inclusive or exclusive bounds, which half to keep) and use it every time. Practise lower bound, upper bound, rotated arrays and search on the answer.
Coding problems
- Count Unique Binary Search Trees (Basic)
- Binary Search Boundary (Intermediate)
- BST Range Sum (Basic)
- BST Successor and Predecessor (Intermediate)
- Smallest Range Across K Lists (Advanced)
- Maximum Flow With Lower Bounds (Basic)
- Validate Binary Search Tree (Intermediate)
- Kth Smallest Value in a BST (Intermediate)
- Convert Sorted Array to BST (Basic)
- Mode Values in a BST (Intermediate)
- Minimum Absolute Difference in BST (Basic)
- Two Sum in a BST (Basic)
- Trim a BST (Intermediate)
- Insert Into a BST (Basic)
- Delete Node in a BST (Intermediate)
- Recover Swapped BST Values (Intermediate)
- Closest Value in a BST (Basic)
- BST From Preorder (Intermediate)
- Maximum Sum BST in Binary Tree (Advanced)
- Alien Dictionary Order (Advanced)
- Ways to Reorder Array to Get Same BST (Advanced)
- Search in Rotated Sorted Array II (Intermediate)
- Balance a Binary Search Tree (Intermediate)
- Optimal Binary Search Tree Cost (Advanced)
- Find in Mountain Array (Advanced)
- Binary Insertion Sort Comparison Count (Intermediate)
Related
- Sliding window problems
- Dynamic programming problems
- Graph problems
- Practice coding problems online
- All interview question topics
Frequently asked questions
How do I get good at binary search problems?
Solve a few problems of each difficulty, name the pattern after you solve each one, and revisit the ones you needed hints for a week later. The list on this page is ordered so you can start with the basic ones.
Can I run binary search problems online here?
Yes. Every problem opens in an editor that runs your code against test cases in Java, Python, C++, Go, JavaScript and six more languages, with no setup.