Please tell why my code is not giving correct solution

please correct my code and try to make changes in it only

hello @harryson
r u using k select algorithm?

no i thought of this logic on my own

can u please debugg it

pls explain ur logic. i m not getting it

basically i tried to solve it with recursion
i first found the index of element to which closest element has to be found
and then made base cases and called for left part first and then for the right side part

ur direction of thinking is correct, but ur logic is not correct.
pls refer this->link

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.