Minimum Difference Element in a Sorted Array
Medium

Problem Statement

Given a sorted array and a target key, find the element in the array that has the minimum absolute difference with the given key.

Examples

1Example 1
Input:
{ "arr": [ 1, 3, 8, 10, 15 ], "key": 12 }
Output:
10
2Example 2
Input:
{ "arr": [ 4, 7, 10 ], "key": 4 }
Output:
4
3Example 3
Input:
{ "arr": [ 4, 7, 10 ], "key": 6 }
Output:
7
Loading...

Sign in to Run Code and Submit