Binary search code problem

ques : https://hack.codingblocks.com/app/contests/1617/199/problem
ans:
https://ide.codingblocks.com/s/308672
by this code some of the test cases are failed.
pls help me out…

@Shantanu07j, this problem is supposed to be done in o(log n) using binary search , when you but you are applying a nested loop which doesn’t serve the purpose , instead use while loop
refer below for correct implementation of binary search :-

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.

@Shantanu07j you have reopen the doubt

would you want to ask something??
or you didn’t understood something then
feel free to ask