Solution: Find the Floor and Ceil of a Number

This review discusses the solution for finding the floor and ceil value of a given number from a sorted array.

We'll cover the following


We can make use of the fact that the array is sorted. So, by a little modification of the binary search algorithm, we can successfully crack this problem. The core idea remains the same: we divide the array at the midpoint and search for the key either in left or right subarray based on the comparison with a given number.

Here is the complete working solution:

Level up your interview prep. Join Educative to access 70+ hands-on prep courses.