What is problem with this code?

sample test cases are passing and I’ve used binary search I don’t know why TLE is occurring for some of the test cases
please help me with this code.

in you can schola the time complexity is O(n) you have to do it in O(log n) check this


If find any difficulty , let me know.

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.