Challenge: Find the Closest Number

In this lesson, we will solve a challenge on finding the closest number to a given number in a list.

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 80+ hands-on prep courses.