Grokking the Coding Interview: Patterns for Coding Questions
Vote
0% completed
Introduction to Modified Binary Search Pattern
You are given a sorted array and a target. Find the smallest value that is greater than or equal to the target, which is called its ceiling.
[1, 3, 8, 10, 15] target = 12 the ceiling is 15
Plain binary search answers a narrower question. It tells you whether the target is present. When the target is absent it returns nothing useful, and here the absence is the interesting part.
You do not need a different algorithm. You need the same one, with two changes.
The first change is what you do when the loop ends. Ordinary binary search returns "not found". But when `start
.....
.....
.....
Like the course? Get enrolled and start learning!