Challenge: Find the Closest Number

Find the closest number to a given number in an array.

Closest number

In any given sorted list, the closest number to a given number is the one whose absolute difference with the given number is closest to zero.

Have a look at the following illustration for a better understanding:

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