Altimetrik interview question

find closest element