You want to master binary search, but where do you start? Which variant should you learn first? How do you progress from basic search to optimization problems?
This roadmap answers all those questions. It's a structured 6-week learning path that takes you from zero to mastery, with curated problems, clear milestones, and a proven progression.
Follow this roadmap, and in 6 weeks, you'll confidently solve any binary search problem in interviews.
How to Use This Roadmap
Time Commitment
- Beginner: 1-2 hours per day, 5 days per week
- Intermediate: 2-3 hours per day, 5 days per week
- Total: 6 weeks to interview-ready
Progression Philosophy
- Master classic binary search before variants
- Understand the math behind each pattern
- Debug systematically on every problem
- Recognize patterns in 30 seconds
- Build intuition for monotonicity
Milestones
- ✅ Week 2: Solve classic binary search problems confidently
- ✅ Week 3: Handle duplicates and bounds correctly
- ✅ Week 4: Master rotated arrays and 2D matrices
- ✅ Week 6: Interview-ready for any binary search problem
Phase 1: Foundations (Weeks 1-2)
Goal: Master classic binary search and understand why it works.
Week 1: Classic Binary Search
Concepts to Learn:
- What is binary search?
- Why sorted data is required
- Monotonicity principle
- Loop conditions and pointer updates
- Off-by-one errors
Required Reading:
- Complete Binary Search Guide - Read sections 1-4
- Why Sorted Data Required
- Off-by-One Errors
Problems to Solve (5 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 1 | Binary Search (#704) | Easy ⭐ | Basic template |
| 2 | Search Insert Position (#35) | Easy ⭐ | Insertion point |
| 3 | Sqrt(x) (#69) | Easy | Integer square root |
| 4 | First Bad Version (#278) | Easy ⭐ | Lower bound variant |
| 5 | Valid Perfect Square (#367) | Easy | Monotonic function |
Practice Template:
# Memorize this template
left, right = 0, len(arr) - 1
while left <= right:
mid = left + (right - left) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -1Checkpoint: Can you solve Binary Search (#704) from memory without any bugs?
Week 2: Debugging and Common Mistakes
Concepts to Learn:
- Integer overflow in mid calculation
- Infinite loop causes
- Wrong loop conditions
- Edge case handling
Required Reading:
Problems to Solve (6 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 6 | Guess Number Higher or Lower (#374) | Easy | Interactive binary search |
| 7 | Arranging Coins (#441) | Easy | Mathematical formula |
| 8 | Find Smallest Letter (#744) | Easy | Upper bound variant |
| 9 | Peak Index in Mountain Array (#852) | Easy | Modified binary search |
| 10 | Count Negative Numbers (#1351) | Easy | Row-wise binary search |
| 11 | Special Array With X Elements (#1608) | Easy | Binary search on answer intro |
Debugging Checklist:
-
Using
mid = left + (right - left) // 2? -
Pointer updates always make progress?
-
Loop condition matches pointer updates?
-
Handling empty arrays?
-
Testing edge cases?
Checkpoint: Can you debug a broken binary search in under 3 minutes?
Phase 2: Bounds and Duplicates (Week 3)
Goal: Master lower bound, upper bound, and handle duplicates correctly.
Week 3: Lower Bound and Upper Bound
Concepts to Learn:
- Lower bound (first >= target)
- Upper bound (first > target)
- Finding first and last occurrence
- The one-character difference (
<vs<=)
Required Reading:
Problems to Solve (7 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 12 | Find First and Last Position (#34) | Medium ⭐⭐ | Both bounds |
| 13 | Single Element in Sorted Array (#540) | Medium | XOR property |
| 14 | Search in Rotated Sorted Array (#33) | Medium ⭐⭐ | Rotated intro |
| 15 | Find Minimum in Rotated Sorted Array (#153) | Medium ⭐⭐ | Find pivot |
| 16 | Find Peak Element (#162) | Medium | Local maximum |
| 17 | Kth Missing Positive Number (#1539) | Easy | Missing numbers |
| 18 | Count Complete Tree Nodes (#222) | Medium | Tree binary search |
Lower Bound Template:
left, right = 0, len(arr)
while left < right:
mid = left + (right - left) // 2
if arr[mid] < target: # <
left = mid + 1
else:
right = mid
return leftUpper Bound Template:
left, right = 0, len(arr)
while left < right:
mid = left + (right - left) // 2
if arr[mid] <= target: # <=
left = mid + 1
else:
right = mid
return leftCheckpoint: Can you explain the difference between < and <= and when to use each?
Phase 3: Advanced Variants (Week 4)
Goal: Master rotated arrays, 2D matrices, and understand the proofs.
Week 4: Rotated Arrays and 2D Matrices
Concepts to Learn:
- Why one half is always sorted in rotated arrays
- Handling duplicates in rotated arrays
- 2D matrix index mapping
- Staircase search for row-column sorted matrices
Required Reading:
- Rotated Sorted Array
- Rotated Array Proof
- Duplicates in Rotated Arrays
- 2D Matrix Search
- 2D Matrix Index Mapping
Problems to Solve (8 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 19 | Search in Rotated Sorted Array II (#81) | Medium ⭐⭐ | With duplicates |
| 20 | Find Minimum in Rotated Sorted Array II (#154) | Hard | Find min with duplicates |
| 21 | Search a 2D Matrix (#74) | Medium ⭐⭐ | Fully sorted matrix |
| 22 | Search a 2D Matrix II (#240) | Medium ⭐⭐ | Row-column sorted |
| 23 | Kth Smallest Element in Sorted Matrix (#378) | Medium | Binary search on answer |
| 24 | Find K-th Smallest Pair Distance (#719) | Hard | Advanced BS on answer |
| 25 | Median of Two Sorted Arrays (#4) | Hard ⭐⭐⭐ | Partitioning |
| 26 | Split Array Largest Sum (#410) | Hard | Optimization intro |
Rotated Array Template:
while left <= right:
mid = left + (right - left) // 2
if arr[mid] == target:
return mid
# Identify which half is sorted
if arr[left] <= arr[mid]:
# Left half sorted
if arr[left] <= target < arr[mid]:
right = mid - 1
else:
left = mid + 1
else:
# Right half sorted
if arr[mid] < target <= arr[right]:
left = mid + 1
else:
right = mid - 1Checkpoint: Can you explain why one half is always sorted in a rotated array?
Phase 4: Binary Search on Answer (Weeks 5-6)
Goal: Master optimization problems using binary search on answer.
Week 5: Minimize Maximum Pattern
Concepts to Learn:
- Binary search on answer space
- Monotonic feasibility
- Feasibility function design
- "Minimize the maximum" pattern
Required Reading:
- Binary Search on Answer
- Why Binary Search on Answer Works
- Minimize Maximum vs Maximize Minimum
- Feasibility Function Mistakes
Problems to Solve (8 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 27 | Koko Eating Bananas (#875) | Medium ⭐⭐⭐ | Classic minimize maximum |
| 28 | Capacity To Ship Packages (#1011) | Medium ⭐⭐ | Greedy grouping |
| 29 | Split Array Largest Sum (#410) | Hard ⭐⭐⭐ | Minimize maximum sum |
| 30 | Minimize Max Distance to Gas Station (#774) | Hard | Floating point BS |
| 31 | Find the Smallest Divisor (#1283) | Medium | Ceiling division |
| 32 | Magnetic Force Between Two Balls (#1552) | Medium ⭐⭐ | Maximize minimum intro |
| 33 | Minimum Number of Days to Make m Bouquets (#1482) | Medium | Time-based feasibility |
| 34 | Cutting Ribbons (#1891) | Medium | Maximize with constraint |
Minimize Maximum Template:
def minimize_maximum(min_val, max_val, is_feasible):
left, right = min_val, max_val
while left < right:
mid = left + (right - left) // 2
if is_feasible(mid):
# mid works, try smaller
right = mid
else:
# mid doesn't work, need larger
left = mid + 1
return leftCheckpoint: Can you identify "minimize maximum" keywords in a problem statement?
Week 6: Maximize Minimum and Interview Mastery
Concepts to Learn:
- "Maximize the minimum" pattern
- Complexity analysis (when it's not O(log n))
- Pattern recognition in 30 seconds
- Interview communication
Required Reading:
Problems to Solve (10 problems):
| # | Problem | Difficulty | Key Learning |
|---|---|---|---|
| 35 | Aggressive Cows (classic) | Hard | Maximize minimum distance |
| 36 | Allocate Minimum Number of Pages | Hard | Book allocation |
| 37 | Minimize the Difference (#1818) | Medium | Absolute difference |
| 38 | Maximum Number of Removable Characters (#1898) | Medium | Binary search on count |
| 39 | Minimum Limit of Balls in a Bag (#1760) | Medium | Minimize maximum balls |
| 40 | Maximum Value at a Given Index (#1802) | Medium | Maximize with constraints |
| 41 | Maximum Running Time of N Computers (#2141) | Hard | Time allocation |
| 42 | Minimize Maximum of Array (#2439) | Medium | Array operations |
| 43 | Successful Pairs of Spells and Potions (#2300) | Medium | Counting pairs |
| 44 | Find in Mountain Array (#1095) | Hard | Multi-step binary search |
Maximize Minimum Template:
def maximize_minimum(min_val, max_val, is_feasible):
left, right = min_val, max_val
result = min_val
while left <= right:
mid = left + (right - left) // 2
if is_feasible(mid):
# mid works, try larger
result = mid
left = mid + 1
else:
# mid doesn't work, need smaller
right = mid - 1
return resultInterview Simulation:
- Set 25-minute timer
- Solve problem from scratch
- Explain solution out loud
- Handle follow-up questions
Checkpoint: Can you solve any binary search problem in under 20 minutes?
Supplementary Resources
Templates to Memorize
1. Classic Binary Search
left, right = 0, len(arr) - 1
while left <= right:
mid = left + (right - left) // 2
if arr[mid] == target:
return mid
elif arr[mid] < target:
left = mid + 1
else:
right = mid - 1
return -12. Lower Bound
left, right = 0, len(arr)
while left < right:
mid = left + (right - left) // 2
if arr[mid] < target:
left = mid + 1
else:
right = mid
return left3. Upper Bound
left, right = 0, len(arr)
while left < right:
mid = left + (right - left) // 2
if arr[mid] <= target:
left = mid + 1
else:
right = mid
return left4. Binary Search on Answer
def solve(min_val, max_val):
def is_feasible(x):
# Check if x works
return check(x)
left, right = min_val, max_val
while left < right:
mid = left + (right - left) // 2
if is_feasible(mid):
right = mid # For minimize
else:
left = mid + 1
return leftCommon Mistakes Checklist
-
Using
(left + right) // 2instead ofleft + (right - left) // 2 -
Wrong loop condition (
<vs<=) -
Using
right = mid - 1when should useright = mid -
Confusing lower bound and upper bound (
<vs<=) -
Not handling duplicates in rotated arrays
-
Wrong feasibility direction (minimize vs maximize)
-
Using floor division when need ceiling
-
Forgetting to update state in greedy feasibility
Pattern Recognition Checklist
1. Is data sorted?
├─ Yes → Classic binary search
└─ Rotated? → Rotated binary search
2. Finding first/last occurrence?
└─ Use lower/upper bound
3. "Minimize maximum" or "maximize minimum"?
└─ Binary search on answer
4. 2D matrix?
├─ Fully sorted → Treat as 1D
└─ Row-column sorted → Staircase search
5. Can verify if answer works?
└─ Check monotonicity → BS on answerProgress Tracking
Week-by-Week Checklist
Week 1:
-
Read Complete Binary Search Guide
-
Solve 5 classic problems
-
Memorize classic template
-
Can solve Binary Search (#704) from memory
Week 2:
-
Read Implementation Mistakes guide
-
Solve 6 problems
-
Understand all 7 common mistakes
-
Can debug in under 3 minutes
Week 3:
-
Read Lower/Upper Bound guides
-
Solve 7 problems
-
Master both bound templates
-
Can explain
<vs<=difference
Week 4:
-
Read Rotated Array and 2D Matrix guides
-
Solve 8 problems
-
Understand rotated array proof
-
Can solve rotated array from memory
Week 5:
-
Read Binary Search on Answer guides
-
Solve 8 problems
-
Master minimize maximum pattern
-
Can write feasibility functions
Week 6:
-
Solve 10 advanced problems
-
Practice interview simulation
-
Achieve 20-minute solve time
-
Interview-ready confidence
Success Metrics
By the end of 6 weeks, you should be able to:
✅ Recognize patterns instantly (< 30 seconds)
✅ Solve easy problems in under 8 minutes
✅ Solve medium problems in under 20 minutes
✅ Write bug-free binary search on first attempt (90%+ of the time)
✅ Debug solutions in under 3 minutes
✅ Explain monotonicity clearly
✅ Design feasibility functions for optimization problems
Beyond the Roadmap
After completing this roadmap:
- Maintain skills - Solve 2-3 binary search problems per week
- Explore advanced topics - Ternary search, fractional cascading
- Teach others - Explaining solidifies understanding
- Apply to real problems - Use in competitive programming
- Review proofs - Deepen mathematical understanding
Final Tips
Do's
✅ Understand the math behind each pattern
✅ Visualize pointer movement on paper
✅ Test edge cases systematically
✅ Practice explaining solutions out loud
✅ Build intuition for monotonicity
✅ Use correct templates consistently
Don'ts
❌ Memorize without understanding
❌ Skip the proof articles
❌ Ignore off-by-one errors
❌ Rush through feasibility functions
❌ Confuse minimize and maximize patterns
❌ Use binary search on unsorted data
Conclusion
This roadmap is your structured path to binary search mastery. Follow it consistently, and in 6 weeks, you'll be interview-ready.
Remember:
- Week 1-2: Master classic binary search
- Week 3: Handle duplicates with bounds
- Week 4: Rotated arrays and 2D matrices
- Week 5-6: Binary search on answer mastery
The journey is systematic, and the reward is confidence. Binary search is a fundamental skill that appears in countless interview problems.
Start with Week 1, Problem #1 (Binary Search #704), and begin your journey to mastery.
Good luck, and happy searching! 🚀
Ready to start? Begin with the Complete Binary Search Guide and solve your first problem today.
Want to Practice LeetCode Smarter?
LeetCopilot is a free browser extension that enhances your LeetCode practice with AI-powered hints, personalized study notes, and realistic mock interviews — all designed to accelerate your coding interview preparation.
Also compatible with Edge, Brave, and Opera
