...
/Solution: Find the Floor and Ceil of a Number in a Sorted Array
Solution: Find the Floor and Ceil of a Number in a Sorted Array
Review various approaches in detail to find the floor and ceiling values of a given number from a sorted array.
Solution 1
The naive approach to this problem would be:
- Traverse the array starting from the 0th
index
to the lastindex
. - Compare value at each index
arr[i]
with the given inputinteger
. - When you reach the maximum value lesser than equal to