Find ceiling of target element in a sorted array

Problem Given a sorted array and a value x, the ceiling of x in sorted array. Assume than the array is sorted in non-decreasing order. Write efficient functions to find floor and ceiling of x. Definition the ceiling of x is the smallest element in array greater than or equal to x. Examples Example 1: Input: arr = [1, 2, 4, 6, 10, 12, 14], x = 5 Output: 6 Explanation: The smallest element greater than or equal to 5 is 6. ...

Find minimum difference Element in sorted array

Problem Given a sorted array and a number. Find the element in the array that has minimum difference with the given number. Example Example 1: Input: a[] = [2, 5, 10, 12, 15], target = 6 Output: 5 Explanation: The difference between the target value '6' and '5' is the minimum. ...

Find floor of target element in a sorted array

Problem Given a sorted array and a value x, find the floor of the key in an array. floor is the greatest element smaller than or equal to x. Assume than the array is sorted in non-decreasing order. Definition floor is the greatest element smaller than or equal to x Examples Example 1: Input: arr = [1, 2, 4, 6, 10, 12, 14], x = 5 Output: 4 Explanation: The largest element less than or equal to 5 is 4 ...

This site uses cookies to improve your experience on our website. By using and continuing to navigate this website, you accept this. Privacy Policy