Concept Flow - Floor and Ceil in Sorted Array
Start
Set low=0, high=n-1
While low <= high
Calculate mid=(low+high)/2
Compare arr[mid
mid
mid
mid
After loop ends
Floor = arr[high
Ceil = arr[low
Return Floor and Ceil
End
We use binary search to find the target or closest elements. If found, floor and ceil are the same. Otherwise, floor is the largest smaller element, ceil is the smallest larger element.
