Skip to content

Latest commit

 

History

History

Find Closest Number in Array

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Given an array of sorted integers. We need to find the closest value to the given number. Array may contain duplicate values and negative numbers.

Input : arr[] = {1, 2, 4, 5, 6, 6, 8, 9}
             Target number = 11
Output : 9
9 is closest to 11 in given array

Input :arr[] = {2, 5, 6, 7, 8, 8, 9}; 
       Target number = 4
Output : 5